如何在具有分组选项的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)
})
}
)
一种方法是存储所有选项及其分组标签的变量,然后搜索该选项来自哪个组。但是,当组之间的选择重叠时,这是行不通的。
答案 0 :(得分:0)
您可以给每个输入一个值,而不是直接使用它们的名称,如下所示:
shinyApp(
ui = fluidPage(
selectInput("state", "Choose a word:",
list(`Building` = list("Apartment"="ap", "Bank"="bk", "Hospital"="hp"),
`Nature` = list("Bank"="bk1", "River"="rv", "Orange"="or"),
`Color` = list("Blue"="bl", "Orange"="or1", "Red"="rd"))
),
textOutput("result")
),
server = function(input, output) {
output$result <- renderText({
paste("You chose", input$state)
})
}
)