2

I have a shiny dashboard below and I would like to know if there is a way to keep left and right sidebar hidden by default when a specific tab is selected. In this case the tab 'Front'. I did it with shinyJs().Is there a way to also hide the 'gear' icons and the ability to open the right sidebar at all from the "Front"? More specifically when the user is in the Front tab the right sidebar display which is enabled when he clicks on the gear icon in the top right corner should not be possible at all. No right sidebar for this tab as it is empty and useless.

## app.R ##
        library(shiny)
        library(shinydashboard)
        library(shinydashboardPlus)
        library(DT)
        library(shinyWidgets)
        library(shinyjs)
        ui <- dashboardPagePlus(
            dashboardHeaderPlus(
                enable_rightsidebar = TRUE,
                rightSidebarIcon = "gears",
                fixed = T
            ),

            dashboardSidebar(
            ),

            dashboardBody(
                useShinyjs(),
                tags$hr(),
                tabsetPanel(
                    id ="tabA",
                    type = "tabs",
                    tabPanel("Front",icon = icon("accusoft")),
                    tabPanel("Data", icon = icon("table")


                    )
                )
            ),
            rightsidebar = rightSidebar(

            )
        )

        server <- function(input, output) {
            observe({
               if (input$tabA == "Front") {
                   addClass(selector = "body", class = "sidebar-collapse")
                   removeClass(selector = "body", class = "control-sidebar-open")
               } else {
                   removeClass(selector = "body", class = "sidebar-collapse")
                   addClass(selector = "body", class = "control-sidebar-open")
               }
            })
        }

        shinyApp(ui = ui, server = server)
ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
firmo23
  • 7,490
  • 2
  • 38
  • 114
  • I don't understand, you want to hide the sidebar panels for all tabs except wen ```Data``` is selected? Currently, being on the tab `Front` hides the sidebar panels – bretauv Mar 19 '20 at 16:06
  • but I want to prevent the ability to display the right if you want – firmo23 Mar 19 '20 at 16:22
  • 1
    Could you add some detail in your post about the expected behavior? What is the app supposed to look like when we start it, what should append if we click on this tab or this one, etc. – bretauv Mar 19 '20 at 16:24

1 Answers1

1

Edit: Here an updated version using updateControlbar can be found.

Please see the following:

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

ui <- dashboardPagePlus(
  dashboardHeaderPlus(
    enable_rightsidebar = TRUE,
    rightSidebarIcon = "gears",
    fixed = T
  ),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    tags$hr(),
    tabsetPanel(
      id ="tabA",
      type = "tabs",
      tabPanel("Front",icon = icon("accusoft")),
      tabPanel("Data", icon = icon("table")
      )
    )
  ),
  rightsidebar = rightSidebar()
)

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

shinyApp(ui = ui, server = server)
ismirsehregal
  • 30,045
  • 5
  • 31
  • 78
  • could u check this based on your answer? https://stackoverflow.com/questions/73791859/the-icon-that-hides-and-seek-right-sidebar-in-shinydashboardplus-is-not-workin – firmo23 Sep 21 '22 at 10:34