问题
I'd like to change values of an inputbox based on another inputbox.
With R Shiny there is a method available: updateSelectInput. But I'm not sure how to use it in flexdashboard.
回答1:
This is quite late but also quite possible.
If this is your first selectInput()
raw_data <- mpg
selectInput(
"manufacturer",
label = "Select manufacturer",
choices = c("All", sort(unique(raw_data$manufacturer)))
)
You can try either of these approaches. This one is overall less code:
renderUI({
df <-
raw_data %>%
filter(
manufacturer == input$manufacturer |
input$manufacturer == "All"
)
selectInput(
"model",
label = "Select model",
choices = c("All", sort(unique(df$model)))
)
})
Or an observeEvent()
. I think this one saves on performance as it only looks at one input, but it's not a huge difference.
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)))
)
})
来源:https://stackoverflow.com/questions/45839542/how-to-use-updateselectinput-in-flexdashboard