Hi everybody! I have a (simplified) app that:
- has a button in the "home page"
- the button opens a modal
- in the modal there is a selectizeInput that needs to be dynamically updated
I can't understand why the updateSelectizeInput doesn't work. What am I doing wrong? Here is the reproducible example:
library(shiny)
name_module_UI <- function(id) {
ns <- NS(id)
selectizeInput(
inputId = ns("name_surname"),
label = "Choose name and/or surname",
choices = NULL,
width = '200%',
multiple = TRUE,
options = list(create = FALSE)
)
}
name_module_SERVER <- function(id, name_surname, surname) {
moduleServer(id, function(input, output, session) {
observe({
updateSelectizeInput(
session,
inputId = "name_surname",
choices = name_surname,
selected = surname
)
})
})
}
modal_module_UI <- function(id) {
ns <- NS(id)
name_module_UI(id = ns("test"))
}
modal_module_SERVER <- function(id) {
moduleServer(id, function(input, output, session) {
name_module_SERVER(
id = "test",
name_surname = c("Davide", "Magno"),
surname = "Magno"
)
})
}
# Main UI
ui <- fluidPage(
actionButton(inputId = "button", label = "Open Modal")
)
# Main server function
server <- function(input, output, session) {
observeEvent(input$button, {
showModal(
modalDialog(
title = "Twice nested UpdateInput",
size = "xl",
modal_module_UI(id = "modal_module"),
easyClose = TRUE
)
)
})
modal_module_SERVER(id = "modal_module")
}
shinyApp(ui, server)
I think it is a timing issue because I put a browser both in the name_module_SERVER and in the name_module_UI functions. When I run shinyApp(ui, server), it:
- immediately stops in the name_module_SERVER
- then I click the button
- it stops in the name_module_UI function
- it opens the modal and nothing more happens, it doesn't enter again in the name_module_SERVER function
How can I call the name_module_SERVER after the modal has been open and the selectizeInput created?
Thanks a lot for your support!
Davide