Skip to content

dashboardUser not displayed when using shinydashboard::sidebarMenuOutput #102

Closed

Description

@DavidBarke

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
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
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.

Activity

  1. DivadNojnarg commented on Feb 25, 2021

    @DivadNojnarg
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions