Here is the module rewriting:
somemod_UI <- function(id) {
ns <- NS(id)
div(style="display:block;",
lapply(1:10, function(i) {
numericInput(paste0(ns("n"), i), paste0("n", i), value = 0)
})
)
}
somemod_Server <- function(id) {
moduleServer(
id,
function(input, output, session) {
observe(
if (input$n10 > 0) print(1)
)
}
)
}
ui <- fluidPage(
actionButton("a", "add UI"),
div(style="display:flex;",
uiOutput("ui_out")
))
server <- function(input, output, session) {
# flags <- reactiveValues()
observeEvent(input$a, {
output$ui_out <- renderUI({
somemod_UI("s1")
})
somemod_Server("s1")
})
}
shinyApp(ui, server)
Like I said, the module is loaded dynamically, so I cannot call the UI on main UI (fluidPage), it has to go inside the renderUI, and then call the server somemod_Server -- whole UI and server are loaded through server on button click, no preloading.
Second, the module is not written by me, I am just loading the module, so I cannot use any "requirement" req statement. The author of the module may or may not use req in the module server, but I don't know. I need to think the worst -- what if they don't use. So just imagine you cannot change anything inside the module server. It will work if I preload everything but will not work if I dynamically load.