Call Module UI through creation of a tabsetPanel

I am currently having troubles making my module UI and server communicating whith an intermediate renderUI creating the layout. Here is a repex with and without the dynamic creation of the tabsetPanel. I guess the problem comes from namespace but I cannot figure out where and how to fix it.
DO NOT WORK :

mod_graphical_general_ui <- function(id){
  ns <- NS(id)
  tagList(
    selectInput(ns("myselect"), "Select a choice", choices = NULL)
)}

mod_graphical_general_server <- function(id, choices = NULL) {
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    updateSelectInput(session, "myselect", choices = choices)
    
  })
}

ui <- bootstrapPage(
  uiOutput("mytabs")
)

server <- function(input, output) {
  mod_graphical_general_server("mymodule", choices = c("aaa", "bbb"))
  
  output$mytabs = renderUI({
    number_of_tabs <- 3
    names_tab <- paste0("Tab", 1:number_of_tabs)
    myTabs = lapply(1: number_of_tabs, function(x) {tabPanel(names_tab[[x]], div(uiOutput(paste0("graphics_tab", x))))})
    do.call(tabsetPanel, c(myTabs))
  })
  
  output$graphics_tab1 <- renderUI({
    return(mod_graphical_general_ui("mymodule"))
  })
}

shinyApp(ui = ui, server = server)

If I remove the step from calling the tabsetPanel, the code works .

mod_graphical_general_ui <- function(id){
  ns <- NS(id)
  tagList(
    selectInput(ns("myselect"), "Select a choice", choices = NULL)
)}

mod_graphical_general_server <- function(id, choices = NULL) {
  moduleServer( id, function(input, output, session){
    ns <- session$ns
    updateSelectInput(session, "myselect", choices = choices)
    
  })
}

ui <- bootstrapPage(
  #uiOutput("mytabs")
  uiOutput("graphics_tab1")
)

server <- function(input, output) {
  mod_graphical_general_server("mymodule", choices = c("aaa", "bbb"))
  
  output$mytabs = renderUI({
    number_of_tabs <- 3
    names_tab <- paste0("Tab", 1:number_of_tabs)
    myTabs = lapply(1: number_of_tabs, function(x) {tabPanel(names_tab[[x]], div(uiOutput(paste0("graphics_tab", x))))})
    do.call(tabsetPanel, c(myTabs))
  })
  
  output$graphics_tab1 <- renderUI({
    return(mod_graphical_general_ui("mymodule"))
  })
}

shinyApp(ui = ui, server = server)

I think it definitely comes from namespace but I cannot understand why. When I check the selectInput id within the source code of the page, it is exactly the same between the two examples. How the dynamic creation of the tabs can influence the namespace ?
Thank you very much for your help !

This topic was automatically closed 54 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.