'Shiny submodule server created ui elements do not appear on input list

I using modules in my shiny app. However, if I nest my modules, I can't get the ui to send back information from ui-elements that are created in the module server-section. There is no problem for ui-elements created in the ui-section, only for elements created in the server-section.

There is no problem with the same module, if I do not nest it.

Here is a small example, where I display a table with data from input$

library(shiny)

# Selection module ----
select_module_ui <- function(id){
    tagList(
        selectInput(inputId = NS(id, "select1"),
                    label = "Select 1 from ui-section",
                    choices = c("Denmark", "Germany"),
                    selected = "Denmark"),
        htmlOutput(outputId = NS(id, "select2_ui")),
        tableOutput(outputId = NS(id, "myinputs"))
    )
}

select_module_server <- function(id) {
    moduleServer(id, function(input, output, session) {

        all_inputs <- reactive({
            myvalues <- NULL
            for(i in 1:length(names(input))){
                myvalues <- as.data.frame(rbind(myvalues,(cbind(names(input)[i],input[[names(input)[i]]]))))
            }
            names(myvalues) <- c("User Input","Last Value")
            myvalues
        })

        output$select2_ui <- renderUI({
            selectInput(inputId = NS(id, "select2"),
                        label = "Select 2 from server-section",
                        choices = c("Denmark", "Germany"),
                        selected = "Denmark")
        })

        output$myinputs <- renderTable({all_inputs()})
    })
}

# Container module -----
container_module_ui <- function(id){
        select_module_ui(id = NS(id, "select_module"))
}

container_module_server <- function(id) {
    moduleServer(id, function(input, output, session) {
        select_module_server(id = "select_module")
    })
}


# Application -----
ui <- fluidPage(
    h2("As a normal module"),
    select_module_ui(id = "select_module_normal"),
    hr(),
    h2("As a submodule within a module"),
    container_module_ui(id = "container_module")
)

server <- function(input, output, session) {
    select_module_server(id = "select_module_normal")
    container_module_server(id = "container_module")
}

shinyApp(ui, server)

Where there is input$ information when not nesting. And no information when nesting.

I suspect it is a problem with my use of NS(id, ...) call in the module_container_server, but the other server elements are displayed correctly (the selectInput and the renderTable). And it does not work to call the select_server using NS(id, ...)

container_module_server <- function(id) {
    moduleServer(id, function(input, output, session) {
        select_module_server(NS(id, "select_module"))
    })
}

Thanks, Lars



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source