【发布时间】:2018-07-24 05:15:57
【问题描述】:
我正在尝试动态更新闪亮应用的下拉列表中的值。因此,如果在下拉分类中选择了值,它应该更新产品系列下拉列表中的值。我在下面的代码中缺少什么。它似乎没有选择任何值,并且仅从 else 条件中获取值。
library(shiny)
library(shinyWidgets)
# Define the UI
ui <- bootstrapPage(
column(3, uiOutput("class_level")),
column(3,uiOutput("product"))
)
# Define the server code
server <- function(input, output) {
output$class_level <- renderUI({
selectInput(
"selected_class",
label = h4("Classification Level"),
choices = list(
"Brand" = "Brand",
"Brand1" = "Brand1",
"Brand2" = "Brand2"
),
selected = "Brand"
)
})
getFlavor <- reactive({
if (input$selected_class =="Brand") {
c( "a " = "a",
"b" = "b",
"c" = "c"
)
}
else if (input$selected_class =="Brand1")
{
c(
"1" = "1",
"2" = "2",
"3" = "3"
)
}
else (input$selected_class =="Brand2")
{
c(
"x" = "x",
"y" = "y",
"z" = "z"
)
}
})
output$product <- renderUI({
pickerInput(
"selected_product",
label = h4("Product Family"),
choices = as.list(getFlavor()),
selected = as.list(getFlavor()),
options = list(
`deselect-all-text` = "None",
`select-all-text` = "Total",
`actions-box` = TRUE
),
multiple = F,
width = "100%"
)
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)
【问题讨论】: