这已经很晚了,但也很有可能。
如果这是你的第一个selectInput()
raw_data <- mpg
selectInput(
"manufacturer",
label = "Select manufacturer",
choices = c("All", sort(unique(raw_data$manufacturer)))
)
您可以尝试这两种方法中的任何一种。这个整体代码更少:
renderUI({
df <-
raw_data %>%
filter(
manufacturer == input$manufacturer |
input$manufacturer == "All"
)
selectInput(
"model",
label = "Select model",
choices = c("All", sort(unique(df$model)))
)
})
或observeEvent()。我认为这可以节省性能,因为它只查看一个输入,但差别不大。
selectInput(
"model",
label = "Select model",
choices = c("All", sort(unique(raw_data$model)))
)
observeEvent(input$manufacturer, {
df <-
raw_data %>%
filter(
manufacturer == input$manufacturer |
input$manufacturer == "All"
)
updateSelectInput(
session = session,
inputId = "model",
choices = c("All", sort(unique(df$model)))
)
})