How do I get the group name from the selected input in a selectInput
dropdown box with grouped choices? For example, how do I get Building
after I select Bank
within Building
and Nature
after I select Bank
within Nature
?
Updated example:
# demoing optgroup support in the `choices` arg
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a word:",
list(`Building` = list("Apartment", "Bank", "Hospital"),
`Nature` = list("Bank", "River", "Orange"),
`Color` = list("Blue", "Orange", "Red"))
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)
One way is to store a variable of all choices and their grouped labels and search which group this choice is from. But this does not work when there are overlapping choices between groups.