I want to be able to switch various parts of my UI on/off using shinyjs show and hide. I need to access parts of the UI outside the module from within a module. Is this possible?
See the attached app code. The show/hide buttons in the main server code work, but those in the module do not.
Thanks for any suggestions.
exampleUI <- function(id) {
ns <- NS(id)
tagList(actionButton(ns("hide_id"), "Module - Hide divs"),
actionButton(ns("show_id"), "Module - Show divs"),
uiOutput(ns("plot_id")))
}
shinyUI(fluidPage(
shinyjs::useShinyjs(),
shinyjs::hidden(tags$div(id = "hidden", "hidden")),
tags$div(id = "shown", "shown"),
actionButton("hide_id", "Hide divs"),
actionButton("show_id", "Show divs"),
exampleUI("eg")))
example <- function(input, output, session)
{
ns <- session$ns
observeEvent(input$hide_id,
{
shinyjs::hide("hidden")
shinyjs::hide("shown")
})
observeEvent(input$show_id,
{
shinyjs::show("hidden")
shinyjs::show("shown")
})
}
shinyServer(function(input, output) {
callModule(example, "eg")
observeEvent(input$hide_id,
{
shinyjs::hide("hidden")
shinyjs::hide("shown")
})
observeEvent(input$show_id,
{
shinyjs::show("hidden")
shinyjs::show("shown")
})
})