Introduction to Shiny Dashboards
Code Example 1
Code
6 / 7
Code Example 1
Code
Code Example 1
r
library(shiny)
library(tidyverse)
ui <- fluidPage(
titlePanel("Clinical Data Monitoring Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("site_filter", "Site", choices = c("All", unique(prepared_data$site)))
),
mainPanel(
plotOutput("enrollment_plot"),
tableOutput("quality_table")
)
)
)
server <- function(input, output, session) {
filtered_data <- reactive({
if (input$site_filter == "All") {
prepared_data
} else {
prepared_data |> filter(site == input$site_filter)
}
})
output$enrollment_plot <- renderPlot({
filtered_data() |>
count(enrollment_date) |>
ggplot(aes(x = enrollment_date, y = n)) +
geom_col() +
labs(x = "Enrollment date", y = "Participants")
})
output$quality_table <- renderTable({
filtered_data() |>
summarise(
participants = n_distinct(participant_id),
missing_consent = sum(is.na(consent_date)),
missing_day28 = sum(is.na(day28_outcome))
)
})
}
shinyApp(ui, server)