Quantcast
Channel: Dynamically set dropdown options based on other dropdown selection - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Dynamically set dropdown options based on other dropdown selection

$
0
0

The following code allows the user to select between 2 datasets in a dropdown and displays all of the columns for the selected dataset. I would like to add a second dropdown that is dynamically cast with the names of the columns in the selected first dropdown so that the user can select to display a single column only. The goal is to be able to add any dataset to the first dropdown and have it's columns listed in the second dropdown.

library(shiny)ui <- shinyUI(  fluidPage(    selectInput("dataset", label = NULL, choices = c("mtcars", "rock")),    tableOutput("contents")  ))server <- function(input, output, session) {  myData <- reactive({    switch(input$dataset,"rock" = rock,"mtcars" = mtcars)  })  output$contents <- renderTable({    myData()  })  observe({    updateSelectInput(session, "myNames",                      label = "myNames",                      choices = myData()$names,                      selected = myData()$names[1])  })}shinyApp(ui, server)

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>