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)
}