a simple shiny app with a sidebar and the main panel
Drop files here
or click to upload
library(shiny)
ui <- fluidPage(
titlePanel("Basic Shiny App"),
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("rock", "pressure", "cars")),
sliderInput("obs", "Number of observations:",
min = 1, max = 50, value = 10)
),
mainPanel(
plotOutput("distPlot"),
tableOutput("dataTable")
)
)
)
server <- function(input, output) {
# Get the selected dataset
datasetInput <- reactive({
switch(input$dataset,
"rock" = rock,
"pressure" = pressure,
"cars" = cars)
})
# Generate plot
output$distPlot <- renderPlot({
data <- head(datasetInput(), input$obs)
plot(data, main = paste("First", input$obs, "rows of", input$dataset))
})
# Generate table
output$dataTable <- renderTable({
head(datasetInput(), input$obs)
})
}
shinyApp(ui = ui, server = server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?