Create a drop-down menu in bright tags using tags

I know, using the following code, I can create a normal dropdown menu in a brilliant,

selectInput("Input1", "Choose you Input:", choices = c('a1'='1','b2'='2')) 

which will create the following dropdown

enter image description here

But I use conditionalPanel and for which I fill in the view of the built-in dropdownmenu , something like this

enter image description here

I use the following code to create these menus.

 conditionalPanel(condition="input.conditionedPanels==3", div(style="display:inline-block", tags$label('Menu1', `for` = 'Sample'), tags$select(id = 'Sample', class="input-small")), div(style="display:inline-block", tags$label('Menu2', `for` = 'Sample1'), tags$select(id = 'Sample1', class="input-small"))) 

My problem I cannot add items to this dropdown menu . I tried values ​​or parameters, but that didn't change anything.

I hope that I have provided enough information, let me know if additional information is required.

+8
html r drop-down-menu shiny
source share
1 answer

You can specify a list of tags tagList . The tags you need are option tags with value attributes. You can build them using mapply

 library(shiny) runApp(list( ui = bootstrapPage( numericInput('n', 'Enter 3 for condition', 3, 0, 10), conditionalPanel(condition="input.n==3", div(style="display:inline-block", tags$label('Menu1', `for` = 'Sample'), tags$select(id = 'Sample', class="input-small", tagList(mapply(tags$option, value = 1:10, paste0(letters[1:10], 1:10), SIMPLIFY=FALSE))) ), div(style="display:inline-block", tags$label('Menu2', `for` = 'Sample1'), tags$select(id = 'Sample1', class="input-small", tagList(mapply(tags$option, value = 1:2, paste0(letters[1:2], 1:2), SIMPLIFY=FALSE))) ) ) , textOutput("cond") ), server = function(input, output) { output$cond <- renderText({ if(input$n == 3){ paste0("Sample value selected =", input$Sample, " Sample1 value selected =",input$Sample1) } }) } )) 

Of course, you can just use selectInput inside the div , for example:

 library(shiny) runApp(list( ui = bootstrapPage( numericInput('n', 'Enter 3 for condition', 3, 0, 10), conditionalPanel(condition="input.n==3", div(style="display:inline-block", selectInput("Sample", "Choose you Input:", choices = c('a1'='1','b2'='2')) ), div(style="display:inline-block", tags$label('Menu2', `for` = 'Sample1'), tags$select(id = 'Sample1', class="input-small", tagList(mapply(tags$option, value = 1:2, paste0(letters[1:2], 1:2), SIMPLIFY=FALSE))) ) ) , textOutput("cond") ), server = function(input, output) { output$cond <- renderText({ if(input$n == 3){ paste0("Sample value selected =", input$Sample, " Sample1 value selected =",input$Sample1) } }) } )) 
+5
source share

All Articles