rshinyjsshinydashboardplus

The icon that hides and seek right sidebar in shinydashboardPlus() is not working


In the shinydashboardPlus() below I activate and deactivate the right sidebar ability based on the tab I use. The issue is that when Im in the 2nd tab I cannot hide the right sidebar by clicking on the icon above it.

## app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(
    
  ),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    tags$hr(),
    tabsetPanel(
      id ="tabA",
      type = "tabs",
      tabPanel("Front",icon = icon("accusoft")),
      tabPanel("Data", icon = icon("table")
      )
    )
  ),
  controlbar = dashboardControlbar()
  
)

server <- function(input, output) {
  observe({
    if (input$tabA == "Front") {
      hide(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
      removeClass(selector = "body", class = "control-sidebar-open")
    } else {
      show(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
      addClass(selector = "body", class = "control-sidebar-open")
    }
  })
}

shinyApp(ui = ui, server = server)

Solution

  • By now we can use shinydashboardPlus::updateControlbar:

    library(shiny)
    library(shinydashboard)
    library(shinydashboardPlus)
    library(shinyjs)
    
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(),
      dashboardBody(
        useShinyjs(),
        tags$script(HTML("$(document).find('body > div.wrapper > header > nav > div:nth-child(4) > ul').css('display', 'none');")),
        tags$hr(),
        tabsetPanel(
          id ="tabA",
          type = "tabs",
          tabPanel("Front",icon = icon("accusoft")),
          tabPanel("Data", icon = icon("table")
          )
        )
      ),
      controlbar = dashboardControlbar(id = "dashboardControlbarID", collapsed = TRUE)
    )
    
    server <- function(input, output) {
      observeEvent(input$tabA, {
        if (input$tabA == "Front") {
          hide(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
        } else {
          show(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
        }
        updateControlbar("dashboardControlbarID")
      }, ignoreInit = TRUE)
    }
    
    shinyApp(ui = ui, server = server)