RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
454 stars 77 forks source link

dashboardUser not displayed when using shinydashboard::sidebarMenuOutput #102

Closed DavidBarke closed 3 years ago

DavidBarke commented 3 years ago

When using userOutput and shinydashboard::sidebarMenuOutput in a certain combination, I observed that the userOutput was not displayed. I tried to figure out under which circumstances this happens.

sidebarMenuOutput on same level works:

container_ui <- function(id) {
  ns <- shiny::NS(id)
  shinydashboardPlus::dashboardPage(
    header = shinydashboardPlus::dashboardHeader(
      userOutput(ns("user"))
    ),
    sidebar = shinydashboardPlus::dashboardSidebar(
      shinydashboard::sidebarMenuOutput(ns("sidebar"))
    ),
    body = dashboardBody()
  )
}
Complete App ```r library(shiny) library(shinydashboardPlus) library(shinydashboard) container_ui <- function(id) { ns <- shiny::NS(id) shinydashboardPlus::dashboardPage( header = shinydashboardPlus::dashboardHeader( userOutput(ns("user")) ), sidebar = shinydashboardPlus::dashboardSidebar( shinydashboard::sidebarMenuOutput(ns("sidebar")) ), body = dashboardBody() ) } container_server <- function(id) { shiny::moduleServer( id, function(input, output, session) { output$sidebar <- shinydashboard::renderMenu({ shinydashboard::sidebarMenu( shinydashboard::menuItem( text = "Menu Item" ) ) }) output$user <- renderUser({ dashboardUser( name = "Divad Nojnarg", image = "https://adminlte.io/themes/AdminLTE/dist/img/user2-160x160.jpg", title = "shinydashboardPlus", subtitle = "Author", footer = p("The footer", class = "text-center"), fluidRow( dashboardUserItem( width = 6, socialButton( href = "https://dropbox.com", icon = icon("dropbox") ) ), dashboardUserItem( width = 6, socialButton( href = "https://github.com", icon = icon("github") ) ) ) ) }) } ) } shinyApp( ui = container_ui("container"), server = function(input, output) { container_server("container") } ) ```

sidebarMenuOutput nested inside a module breaks the dynamic header. In this case the content for dashboardUser is not displayed. In the page inspector I see that the <li> element that should contain the dashboardUser has class shiny-bound-input but no children. Therefore I suspect there is an issue with the output binding.

container_ui <- function(id) {
  ns <- shiny::NS(id)

  shinydashboardPlus::dashboardPage(
    header = shinydashboardPlus::dashboardHeader(
      userOutput(ns("user"))
    ),
    sidebar = shinydashboardPlus::dashboardSidebar(
      sidebar_menu_ui(ns("sidebar"))
    ),
    body = dashboardBody()
  )
}

sidebar_menu_ui <- function(id) {
  ns <- shiny::NS(id)

  shinydashboard::sidebarMenuOutput(ns("sidebar"))
}
Complete App ```r library(shiny) library(shinydashboardPlus) library(shinydashboard) sidebar_menu_ui <- function(id) { ns <- shiny::NS(id) shinydashboard::sidebarMenuOutput(ns("sidebar")) } sidebar_menu_server <- function(id) { shiny::moduleServer( id, function(input, output, session) { output$sidebar <- shinydashboard::renderMenu({ shinydashboard::sidebarMenu( shinydashboard::menuItem( text = "Menu Item" ) ) }) } ) } container_ui <- function(id) { ns <- shiny::NS(id) shinydashboardPlus::dashboardPage( header = shinydashboardPlus::dashboardHeader( userOutput(ns("user")) ), sidebar = shinydashboardPlus::dashboardSidebar( sidebar_menu_ui(ns("sidebar")) ), body = dashboardBody() ) } container_server <- function(id) { shiny::moduleServer( id, function(input, output, session) { output$user <- renderUser({ dashboardUser( name = "Divad Nojnarg", image = "https://adminlte.io/themes/AdminLTE/dist/img/user2-160x160.jpg", title = "shinydashboardPlus", subtitle = "Author", footer = p("The footer", class = "text-center"), fluidRow( dashboardUserItem( width = 6, socialButton( href = "https://dropbox.com", icon = icon("dropbox") ) ), dashboardUserItem( width = 6, socialButton( href = "https://github.com", icon = icon("github") ) ) ) ) }) sidebar_menu_server("sidebar") } ) } shinyApp( ui = container_ui("container"), server = function(input, output) { container_server("container") } ) ```

The following error appears in the JS console: jserror

I don't observe this issue using the current CRAN release.

DivadNojnarg commented 3 years ago

Well spotted thanks! ensureActivatedTab was not in the global scope, therefore not visible to the output-binding.js script where it is also needed.