如何从selectInput
具有分组选项的下拉框中的选定输入中获取组名称?Building
例如,在我选择Bank
内Building
和选择内Nature
之后如何获得?Bank
Nature
更新示例:
# 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)
})
}
)
一种方法是存储所有选项及其分组标签的变量,然后搜索该选项来自哪个组。但是当组之间有重叠的选择时,这不起作用。