Hello,
I am having some trouble with nested modules. I am trying to update an input based on the change in another input using a nested module approach. I fully get how to do this without modules. In the advanced case I would like to pass an arbitrary module creating function into another module.
Here is the simple reprex.
The outer module is observing the first input and after detecting the change in the first input, is calling the inner module.
The inner module is supposed to change the choices in the second input.
If I run these separately, they work. However, when I nest them, they do not work.
I think the reason is that the inner module is looking for the namespace = 2 INSIDE of the namespace = 1. So then the updateselecticizeInput is looking for a something like 1-2-input$value. This sort of makes sense to me.
I demonstrate that this is true by literally labeling the namespace of the input as "1-2".
So how can I change the code below to ensure that the inner module is looking in the global namespace instead of the local one provided by the outer function?
Thanks!
Anatoliy
library(shiny)
outer = function(id) {
moduleServer(id,
function(input, output, session) {
observeEvent(input$value, {
print(paste("outer = ", input$value))
inner("2")
})
})
}
inner = function(id) {
moduleServer(id, function(input, output, session) {
# using this as a print statement to check for detection
observeEvent(input$value, {
print(paste("inner = ", input$value))
})
print("Calling inner module")
## ideally I want to call this
# updateSelectizeInput(session, inputId = "value", choices = "x")
})
}
listUI = function(index, phrasing, level)
{
ns <- NS(index)
selectizeInput(inputId = ns("value"), label = phrasing, choices = level)
}
ui <- fluidPage(
titlePanel("module nesting"),
mainPanel(
listUI(index = "1", phrasing = "test", level = c("a", "b")),
listUI(index = "2", phrasing = "test", level = c("c", "d")), ## I want this one
listUI(index = "1-2", phrasing = "test", level = c("c", "d")) ## not this one
)
)
server <- function(input, output) {
outer("1")
}
shinyApp(ui = ui, server = server)