For record, also the version with updateMultiInput is possible when wrapped in observe().
It is also most desirable in my case because multiInput will be hidden in the dropdownButton widget. The update version renders the table on the start of the app (see code example 1) instead of after clicking the dropdownButton (code example 2) with renderUI.
#VERSION1
#option with updateinput with widgets
data("murders")
ui = fluidPage(
selectInput("region", "Select region:", choices = unique(murders$region)),
dropdownButton(
inputId = "Button",
circle = TRUE,
status = "danger",
icon = icon("gear"),
multiInput(
"state",
"Selected state:",
choices = "",
width = "600px"
)
),
dataTableOutput("tbl")
)
server = function(input, output, session){
df =
reactive({
murders %>%
filter(region == input$region)
})
output$tbl = renderDataTable(df()) # check if global filter works OK
states = reactive({as.character(unique(df()$state))})
observe({
updateMultiInput(
session,
"state",
selected = "",
choices = states())
}
)
}
shinyApp(ui, server)
#VERSION2
# option with renderUI
library(dslabs)
data("murders")
ui = fluidPage(
selectInput("region", "Select region:", choices = unique(murders$region)),
dropdownButton(
inputId = "Button",
circle = TRUE,
status = "danger",
icon = icon("gear"),
uiOutput("state")
),
dataTableOutput("tbl")
)
server = function(input, output, session){
df =
reactive({
murders %>%
filter(region == input$region)
})
df1 = reactive({
df() %>%
filter(state %in% input$state)
})
output$state = renderUI(
multiInput(
inputId = "state",
label = "Select state",
selected = unique(df()$state),
choices = unique(df()$state)
)
)
output$tbl = renderDataTable(df1()) # check if global filter works OK
}
shinyApp(ui, server)