Module not returning inputs

Shiny Modules noob here, so please bear with me. I have code in a shiny app that dynamically creates selectInputs and I am trying to modularize that code. I can successfully create the selectInputs, but can't return said selections from the module. I've distilled the issue down to the following reprex. It must be in the map_chr line, but I can't seem to figure it out. Any help would be appreciated!

groupIconsUI <- function(id) {
    ns <- NS(id)
    uiOutput(ns("selectIcons"))
}

groupIcons <- function(id,groups) {
    moduleServer(id, function(input, output, session) {
       output$selectIcons <- renderUI({
            selectInputs <- lapply(groups, function(id){
                icons = c("","!","@")
                selectInput(paste0(id), label = paste0(id), choices = icons)
            })
            do.call(tagList, selectInputs)
        })
        
        group_icons <- reactive( map_chr(groups, ~ input[[.x]] %||% "") )
    })
}

DynamicInputsApp <- function(){
    ui <- fluidPage(
        groupIconsUI("test"),
        verbatimTextOutput("icons_output")
    )
    
    server <- function(input, output) {
        test_groups = c("A","B","C")
        icons <- groupIcons("test",test_groups)
        output$icons_output <- renderPrint(icons())
    }
    shinyApp(ui, server)
}   

Solved. Reread this ARTICLE, and realized I needed to use the namespaces for the various selectInputs inside the renderUI function. Here is the corrected selectInput call:

            selectInput(inputId = session$ns(paste0(id)), label = paste0(id), choices = icons)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.