...I'm having some issues getting an observe event to trigger when in a module. The basic idea is a button to clear the selections in a multi select input. Any help is greatly appreciated!
The non module version, shown below, works as expected. Clicking the button clears the selection
library(shiny)
store_list <- c(1:75)
ui <- fluidPage(
selectInput(
"store_ids", "Select Stores", store_list,
multiple = TRUE
,selected = c(1,19,68,69)
)
,actionButton("deselect_all_stores", "Deselect All Stores")
)
server <- function(input, output, session) {
observeEvent(input$deselect_all_stores, {
print('deselect all')
updateSelectInput(session, 'store_ids', selected =character(0))
})
}
shinyApp(ui = ui, server = server)
When moved into a module, nothing is happening when the button is clicked.
library(shiny)
store_list <- c(1:75)
testUI <- function(id, store_list) {
fluidRow(
#Store Select
selectInput(
NS(id,"store_ids"), "Select Stores", store_list,
multiple = TRUE
,selected = c(1,19,68,69)
)
,actionButton("deselect_all_stores", "Deselect All Stores")
)
}
testServer <- function(id) {
moduleServer(id, function(input, output, session) {
# Deselect All
observeEvent(input$deselect_all_stores, {
print('deselect all')
updateSelectInput(session, 'store_ids', selected =character(0))
})
})
}
ui <- fluidPage(
testUI('template1', store_list)
)
server <- function(input, output, session) {
testServer('template1')
}
shinyApp(ui = ui, server = server)