I want to create a shiny app that contains two side bars and the second side bar's drop down is based on the result of the first side bar. I have to datasets from MySQL database and store in data frame, I want to make a Rshiny app which user can first choose which datasets they want to visualize at the first side bar, and then choose which Participants to visualize in the second side bar. The dataset contains the Participants, their races number, and scores.
Below is the datasets:
Participant| Race_number|Score
P1|R1|2
P1|R2|3
P2|R1|4
P2|R2|7
P3|R1|8
P3|R2|9
P4|R1|9
P4|R2|5
Dataset2
Participant| Race_number|Score
P1|RR1|2
P1|RR2|7
P2|RR1|4
P2|RR2|7
P3|RR1|9
P3|RR2|9
The first side bar with a drop down showing "Dataset1" and "Dataset2", after the users choose Dataset1 for example, the second side bar will show a drop down with "P1-P4", If the users choose Dataset2, the second side bar will show a drop down with "P1-P3".
Below is my code so far and when I run the app the second slide bar's drop down doesn't show up.
library(shiny)
library(DBI)
library(RMySQL)
# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("Participants"),
sidebarLayout(
sidebarPanel(
selectInput("Dataset","Please select a dataset:",choices = c("Dataset1", "Dataset2")),
uiOutput("Participants")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("barplot")
)
)
)
# Define server logic required to draw a histogram
server <- function(output, input)({
var <- reactive({
switch(input$Dataset,
"Dataset1" = names(Dataset1$Participant),
"Dataset2" = names(Dataset2$Participant)
})
output$Participants <- renderUI({
selectInput("Participants", "Select the participant", choices = var())
})
})
# Run the application
shinyApp(ui = ui, server = server)
Can anyone tell me why my code doesn't work?