I'm running into what I think is a problem with namespaces and nested shiny modules.
The nested structure of my shiny modules is working, but for the inner module, I need it to generate a UI within the server portion of the module.
Each inner module should produce the following:
A header ("Inside the Generated UI")
some verbatimTextOutput ("something generated")
A chart
The reprex below only produces the header and not the verbatimTextOutput or the plotOutput.
This feels like a namespace problem, but I can't figure out how to fix it.
library(shiny)
inner_UI <- function(id){
ns <- NS(id)
tagList(
h4("inner_UI:", id),
uiOutput(ns("theGeneratedUI")),
verbatimTextOutput(ns("someText"))
)
}
innerServer <- function(id){
moduleServer(id, function(input, output, session) {
ns <- NS(id)
output$someText <- renderText({
"something"
})
output$someTextGenerated <- renderText({
"something Generated"
})
output$theChart <- renderPlot({
t.x <- sample(1:25, 25)
t.y <- sample(1:25, 25)
t.df <- data.frame(x=t.x, y=t.y)
theOutput <- ggplot(data=t.df) +
geom_point(aes(x=x,y=y)) +
ggtitle(paste0("The title:"))
theOutput
})
output$theGeneratedUI <- renderUI({
theOutput <- tagList(
h5("Inside theGeneratedUI"),
verbatimTextOutput(ns("someTextGenerated")),
plotOutput(ns("theChart"))
)
theOutput
})
})
}
outer_UI <- function(id) {
ns <- NS(id)
tagList(
fluidRow(
column(4, inner_UI(ns("inner1"))),
column(4, inner_UI(ns("inner2"))),
column(4, inner_UI(ns("inner3")))
)
)
}
outerServer <- function(id) {
moduleServer(id, function(input, output, session) {
ns <- NS(id)
innerServer("inner1")
innerServer("inner2")
innerServer("inner3")
})
}
ui <- fluidPage(
outer_UI("outer1")
)
server <- function(input, output, session) {
outerServer("outer1")
}
shinyApp(ui, server)