So I have done something which seems to work, but I don't know if it is actually doing what I expect it to be doing, if it is having possible unintended consequences, or if there is a better way to get at what I am trying to achieve.
I am trying to write a Shiny module that creates and displays a modal, however, I want the UI of the modal to be created by the end user of the module. This can of course be done by passing a list of UI components into the module as a parameter. However, when doing this you lose the namespace benefits of the module which I would like to be able to preserve. So what I am doing currently is passing the inputs into the module as a parameter, and then within the module manually changing the id of the inputs. This is only a simple example of what I am doing, where the modalUI parameter is only a list of one shiny input.
modalModule2UI <- function(id, modalUI) {
ns <- NS(id)
modalUI
}
modalModule2 <- function(input, output, session, id, title, modalUI) {
# Modify modalUI ids
modalUI[[1]][[3]][[2]]$attribs$id <- session$ns(modalUI[[1]][[3]][[2]]$attribs$id)
shiny::showModal(
shiny::modalDialog(
title = title,
modalModule2UI(gsub("-", "", session$ns("")), modalUI),
footer =
list(
shiny::modalButton("Cancel"),
shiny::actionButton("irisInsert", "Save")
)
)
)
}
# And this would be how the module is called
observeEvent(input$floweradd2, {
foo <- list(
numericInput("test", "test", 0)
)
callModule(modalModule2, id = "flowersMod2", title = "Hello", modalUI = foo)
})
So this is a multi part question, is it ok to manipulate an input like this? It seems to function properly, but can this have unintended consequences? Is there a better or different way to approach this issue?