Drop files here
or click to upload
library(shiny)
library(ggplot2)
# Generate mock data
set.seed(123)
experiment_data <- data.frame(
Time = seq(0, 11, by=1),
Control = cumsum(rnorm(12, mean=0.5, sd=0.2)),
Treatment_A = cumsum(rnorm(12, mean=0.8, sd=0.2)),
Treatment_B = cumsum(rnorm(12, mean=1.2, sd=0.3))
)
# Define UI
ui <- fluidPage(
theme = bslib::bs_theme(bootswatch = "flatly"),
titlePanel("Gene Expression Analysis"),
sidebarLayout(
sidebarPanel(
selectInput("treatment", "Select Treatment Group:",
choices = c("Control", "Treatment_A", "Treatment_B")),
radioButtons("scale", "Y-axis Scale:",
choices = c("Linear" = "linear", "Log" = "log"),
selected = "linear"),
checkboxInput("show_ci", "Show Confidence Interval", TRUE),
hr(),
helpText("This interactive visualization shows relative gene expression levels over time for different treatment conditions.")
),
mainPanel(
h3("Expression Profile"),
plotOutput("expression_plot"),
br(),
div(style = "color: #666;",
"Note: Data shown represents a simulated time-course experiment measuring relative gene expression levels.",
br(),
"Statistical analysis includes locally-weighted regression (LOESS) with 95% confidence intervals.")
)
)
)
# Define server logic
server <- function(input, output) {
output$expression_plot <- renderPlot({
treatment <- input$treatment
p <- ggplot(experiment_data, aes(x = Time, y = .data[[treatment]])) +
geom_point(size = 3, color = "#2c3e50") +
labs(
x = "Time (hours)",
y = "Relative Expression Level",
title = paste(gsub("_", " ", treatment), "Group"),
subtitle = "Time Course Analysis"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 16, face = "bold"),
plot.subtitle = element_text(size = 12, color = "#666666"),
axis.title = element_text(size = 12),
panel.grid.minor = element_blank()
)
if(input$scale == "log") {
p <- p + scale_y_log10()
}
p <- p + geom_smooth(
method = "loess",
se = input$show_ci,
color = "#e74c3c",
fill = "#e74c3c40"
)
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?