2
votes

New to Shiny and can't seem to find this inforamtion yet: I am making an app with two selectInput drop-downs such that the second (highlighted in yellow) is dependant on the first.

enter image description here

This is for data exploration and basically goes through different folder contents. Here's what I would like to have:

  ui <- fluidPage(
  selectInput(inputId = "site", label = "Select Site", choices = dir(basepath)),
  selectInput(inputId = "duct", label = "Select Duct", 
              choices = dir(grep(input$site, dir(basepath, full.names = T), val = T)))
)

The above code does not work, clearly. I am not sure how to use input$site in another input function.

I found some answers: Displaying multiple inputbox on selecting multiple variables using selectinput function in R Shiny and using conditionalPanel in Shiny ui.R and server.R: different selectInput based on a condition but they are not directly applicable since I don't have an exhaustive list of possible options for the first input (inputId = "site").

1

1 Answers

4
votes

I've created a small example based on the mtcars dataset. Here you will find that the gears from the selectInput site will subset the data of and will return the second selectInput called duct which only displays the selected values from the first one:

library(shiny)

ui <- basicPage(
  headerPanel("Test Shiny App"),
  sidebarPanel(
    selectInput(inputId = "site", label = "Select Site", choices = unique(mtcars$gear)),
    uiOutput("dynamicui")),
  mainPanel()
)

server <- function(input, output, session){
  output$dynamicui <- renderUI({
    selectInput(inputId = "duct", label = "Select Duct", choices = rownames(mtcars)[mtcars$gear %in% input$site])
  })
}
runApp(list(ui = ui, server = server))