Shiny module access output outside namespace

Viewed 2119

I need my Shiny module to hide/show a div outside of the namespace. I tried passing the div id to the module server function and using shinyjs to show/hide it but that is not working. I'm not getting an error, it just doesn't show/hide the div.

I know the Shiny module documentation says modules cannot access outputs outside the namespace. The docs do, though, give a way for the module to access inputs outside the namespace using reactives.

Does anyone know if there is a way for a Shiny module to access an output outside the namespace?

Here is what I'm trying to do:

### ui.R ###
header <- dashboardHeader(
  title = a(href = 'http://google.com')
)

dashboardPage(
  skin = 'black',
  header,

  dashboardSidebar(
    sidebarMenu( id='tabs',
             menuItem('Edit Existing Client', tabName = 'client-info')
    )),

  dashboardBody(
    useShinyjs(),
    fluidRow(
      tabItems(
        tabItem(tabName = "client-info",
                div(selectClientModuleUI("clientinfons")),
                div(id='editclientinfo', uiOutput('editclientstuff'))
        )
      )
    )
  )
)

### server.R ###
shinyServer(function(session,input, output) {

  output$editclientstuff <- renderUI({
    div(
      fluidRow(
        column(6,
           textInput('editname', "Display name", value ='Testing name')
        ),
        column(6,
               numericInput('editastart','Start', value ='3') 
        )
      )
    )
  })


  callModule(selectClientModule, 'clientinfons', 'editclientinfo')
  shinyjs::hide(id='editclientstuff')
})

### in global.R ###
selectClientModuleUI <- function(id){
  ns <- NS(id)

  clientlist = c(0, 1, 2)
  names(clientlist) = c('Choose client', 'Fred', 'Kim')

  div( 
    selectInput(ns('selectclient'), 'Select client to edit', choices = clientlist, selected = NULL, multiple = FALSE)
  )
}

selectClientModule <- function(input, output, session, divtoshow = ''){
  observeEvent(input$selectclient, {
    if (!is.null(input$selectclient) && input$selectclient > 0){
      print(paste0("showing ", divtoshow))
      shinyjs::show(divtoshow)
    }
  })

}
1 Answers
Related