Shiny App

#| '!! shinylive warning !!': |
#|   shinylive does not work in self-contained HTML documents.
#|   Please set `embed-resources: false` in your metadata.
#| standalone: true
#| viewerHeight: 650

library(shiny)
library(tidyverse)

# Embedded data
df_clean <- tibble(
  channel = c("Organic Social", "Direct", "Organic Search", "Unassigned", "Paid Search", "Referral"),
  sessions = c(367, 197, 95, 33, 4, 2),
  engaged_sessions = c(267, 83, 59, 19, 0, 0),
  form_starts = c(24, 14, 3, 1, 0, 0)
) %>%
  mutate(high_intent_rate = form_starts / sessions)

ui <- fluidPage(
  titlePanel("Channel Engagement Explorer"),
  sidebarLayout(
    sidebarPanel(
      selectInput(
        inputId = "metric",
        label   = "Select a metric:",
        choices = c("sessions", "engaged_sessions", "form_starts", "high_intent_rate")
      ),
      checkboxGroupInput(
        inputId  = "channels",
        label    = "Select channels to include:",
        choices  = c("Organic Social", "Direct", "Organic Search", "Unassigned", "Paid Search", "Referral"),
        selected = c("Organic Social", "Direct", "Organic Search", "Unassigned", "Paid Search", "Referral")
      )
    ),
    mainPanel(
      textOutput("title"),
      plotOutput("bar_chart"),
      plotOutput("scatter_plot")
    )
  )
)

server <- function(input, output) {

  output$title <- renderText(
    paste("Showing:", input$metric)
  )

  output$bar_chart <- renderPlot({
    df_clean %>%
      filter(channel %in% input$channels) %>%
      ggplot(aes(x = reorder(channel, .data[[input$metric]]), y = .data[[input$metric]], fill = channel)) +
      geom_col(show.legend = FALSE) +
      coord_flip() +
      labs(
        title = paste(input$metric, "by channel"),
        x     = "Channel",
        y     = input$metric
      ) +
      theme_minimal()
  })

  output$scatter_plot <- renderPlot({
    df_clean %>%
      filter(channel %in% input$channels) %>%
      ggplot(aes(x = sessions, y = high_intent_rate, color = channel)) +
      geom_point(size = 5) +
      geom_text(aes(label = channel), vjust = -1, show.legend = FALSE) +
      labs(
        title = "Sessions vs. High-Intent Rate",
        x     = "Sessions",
        y     = "High-Intent Rate"
      ) +
      theme_minimal() +
      theme(legend.position = "none")
  })
}

shinyApp(ui, server)