Drop files here
or click to upload
library(shiny)
library(ggplot2)
library(bslib)
# Generate mock data
set.seed(123)
data_sample <- data.frame(
Time = seq(0, 11, by=1),
Series_A = cumsum(rnorm(12, mean=0.5, sd=0.2)),
Series_B = cumsum(rnorm(12, mean=0.8, sd=0.2)),
Series_C = cumsum(rnorm(12, mean=1.2, sd=0.3))
)
# Define UI showcasing bslib components
ui <- page_fillable(
theme = bs_theme(
bootswatch = "flatly",
primary = "#3498db",
success = "#2ecc71"
),
# Page title
h1("Interactive Data Dashboard", class = "text-center mb-4"),
# Value boxes row
layout_columns(
col_widths = c(4, 4, 4),
value_box(
title = "Records",
value = "12",
showcase = icon("database"),
theme = "primary"
),
value_box(
title = "Time Range",
value = "12 hrs",
showcase = icon("clock"),
theme = "success"
),
value_box(
title = "Data Series",
value = "3",
showcase = icon("chart-line"),
theme = "info"
)
),
br(),
# Main content with tabs
navs_tab_card(
id = "main_tabs",
title = "Data Dashboard",
nav_panel(
"Visualization",
layout_columns(
col_widths = c(4, 8),
# Controls card
card(
card_header("Plot Controls"),
card_body(
selectInput("series", "Data Series:",
choices = c("Series A" = "Series_A", "Series B" = "Series_B", "Series C" = "Series_C"),
selected = "Series_A"),
radioButtons("scale", "Y-axis Scale:",
choices = c("Linear" = "linear", "Log" = "log"),
selected = "linear"),
checkboxInput("show_ci", "Show Confidence Band", TRUE),
checkboxInput("show_points", "Show Data Points", TRUE),
hr(),
helpText("Configure the visualization options using the controls above.")
)
),
# Plot card
card(
card_header("Data Plot"),
card_body(
plotOutput("data_plot", height = "400px")
)
)
)
),
nav_panel(
"Data Summary",
card(
card_header("Dataset Overview"),
card_body(
h4("Data Description"),
p("This dataset contains simulated time-series data across different data series over a 12-hour period."),
br(),
layout_columns(
col_widths = c(6, 6),
div(
h5("Data Series:"),
tags$ul(
tags$li("Series A: Baseline values"),
tags$li("Series B: Medium variance"),
tags$li("Series C: High variance")
)
),
div(
h5("Technical Details:"),
tags$ul(
tags$li("Data points: 0-11 hours"),
tags$li("Type: Simulated data"),
tags$li("Smoothing: LOESS regression")
)
)
),
br(),
div(class = "alert alert-info",
icon("info-circle"), " ",
"This is a demonstration app showcasing bslib UI components with sample data."
)
)
)
),
nav_panel(
"Settings",
card(
card_header("Application Settings"),
card_body(
h4("Theme Configuration"),
p("This app uses the bslib package for modern Bootstrap styling."),
accordion(
accordion_panel(
"UI Components Used",
tags$ul(
tags$li("page_fillable(): Modern page layout"),
tags$li("value_box(): Key metrics display"),
tags$li("layout_columns(): Responsive grid system"),
tags$li("navs_tab_card(): Tabbed navigation"),
tags$li("card(): Content containers"),
tags$li("accordion(): Collapsible content")
)
),
accordion_panel(
"Styling Features",
tags$ul(
tags$li("Bootstrap 5 components"),
tags$li("Flatly bootswatch theme"),
tags$li("Custom primary and success colors"),
tags$li("Responsive design"),
tags$li("Font Awesome icons")
)
)
)
)
)
)
)
)
# Define server logic
server <- function(input, output) {
output$data_plot <- renderPlot({
selected_series <- input$series
p <- ggplot(data_sample, aes(x = Time, y = .data[[selected_series]])) +
labs(
x = "Time (hours)",
y = "Value",
title = paste(gsub("_", " ", selected_series), "Data Plot"),
subtitle = "Time Series Analysis"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 16, face = "bold", color = "#2c3e50"),
plot.subtitle = element_text(size = 12, color = "#666666"),
axis.title = element_text(size = 12),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = "white", color = NA)
)
# Add points if selected
if(input$show_points) {
p <- p + geom_point(size = 3, color = "#3498db", alpha = 0.8)
}
# Apply scale transformation
if(input$scale == "log") {
p <- p + scale_y_log10()
}
# Add smooth line
p <- p + geom_smooth(
method = "loess",
se = input$show_ci,
color = "#e74c3c",
fill = "#e74c3c",
alpha = 0.3,
linewidth = 1.2
)
p
})
}
# Run the application
shinyApp(ui = ui, server = server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?