Problems nesting modules in shiny and using renderUI
jogugil opened this issue · comments
I have to call a module within another module to display a dataset filter. So the construction of the filter is dynamic and is done within a renderUI.
The problem is that it doesn't show me the filter.
I have created a code that exemplifies my problem.
I have two modules:
inner and outer.
From outer and I call inner.
If the call is made from a renderUI of outer (filter3), the button is not displayed.
It must be a namespace (ns) problem but I can't figure out why.
innerUI <- function(id) {
ns <- NS(id)
hidden(
actionButton(
NS(id, "filter"),
label = NULL,
icon = icon("filter"),
style = "margin-left: 0px;"
)
)
}
outerUI <- function(id) {
ns <- NS(id)
wellPanel(
innerUI(ns("inner1")),
uiOutput(ns("list_dtf"))
)
}
innerServer <- function(id,
data = reactive(NULL),
hide = FALSE,
hover_text = NULL) {
# SERVER
moduleServer(id, function(input, output, session) {
# NAMESPACE
ns <- session$ns
print("!hide")
if (!hide) {
print(hide)
shinyjs::show("filter")
print('show("filter")')
print(id)
if(!is.null(hover_text)) {
addTooltip(session = session,
id = ns("filter"),
title = hover_text)
}
} else {
print("escondo el filter")
}
}
)
}
outerServer <- function(id) {
moduleServer(
id,
function(input, output, session) {
ns <- session$ns
innerResult1 <- innerServer("inner1", hover_text="prueba tooltip 1")
innerResult3 <- innerServer( "inner3", hover_text="prueba tooltip 3")
output$list_dtf <- renderUI({
div(
h2("1 OTRO FILTRO:"),
innerUI(session$ns("inner3")),
h2("2 OTRO FILTRO:")
)
})
}
)
}
ui <- fluidPage(
wellPanel(
titlePanel("Select of Data File"),
useShinyjs(),
outerUI ("select_data_file"),
innerUI("inner2")
)
)
# server
server <- function(input, output, session){
outerServer ("select_data_file")
innerServer("inner2",hide = FALSE,hover_text="prueba tooltip2")
}
shinyApp(ui, server)
In the past users have opened issues multiple times claiming shinyjs breaks with nested modules, and it was always a user error. At this point I'm 99.9% sure that there is no problem with renderUI in nested modules. If you have a truly minimal reprex that makes it easy to test I might look into this, but the above code is not a minimal reprex (it's quite long, it doesn't run as-is, it contains extra packages, and it contains lines that aren't needed), so I'm closing this issue.
´that's not the problem innerResult1 <- innerServer("inner1", hover_text="test tooltip 1") innerResult3 <- innerServer( "inner3", hover_text="test tooltip 3") The issue is in the inner3 that is invoked within a renderUI