3

Can someone help me out with the right css code to allow me to

(1) Have the dashboardControlbar i.e. the right sidebar (previously known as rightSidebar in earlier versions of shinydashboardPlus < 2.0.0) to be open on start-up

(2) Have the option to fully collapse the right controlbar when the gears icon is clicked

enter image description here (clicking the gears on the right do not allow collapsing of the right controlbar, left works fine)

This post follows on from this one which addresses the above scenario but is only valid for the earlier versions of shinydashboardPlus < 2.0.0 there have been major breaking changed in the latest version of the package and internal functions have been changed.

In the example code below I am able to achieve (1) by adding some tags to the body e.g tags$body(class="skin-blue sidebar-mini control-sidebar-open", dashboardPagePlus(...).

I cannot achieve (2). In previous versions sidebar_fullCollapse = TRUE could be called with dashboardPagePlus (now called dashboardPage) and this is no longer an argument to the function.

I have tried using a css inspector tool with the new examples in the package (with version 2 run shinydashboardPlusGallery()) but cannot figure out how to do it or what the right css is.

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
data(iris)

header <- dashboardHeader(title = "Demo")

sidebar <- dashboardSidebar(
  selectInput(
    inputId = "slect",
    label = "Selection Menu",
    selected = "a",
    choices = LETTERS[1:3]
  ),
  p("Write something here..."),
  minified = FALSE
)

body <- dashboardBody(
  tags$script('
      $(".navbar-custom-menu").on("click",function(){
        $(window).trigger("resize");
      })'
  ),
  fluidPage(
    plotOutput(
      "scatter",
      height = "700px",
      width = "100%"
    )
  )
)

controlbar <- dashboardControlbar()

ui <- tags$body(class="skin-blue right-sidebar-mini control-sidebar-open", 
                dashboardPage(header,
                              sidebar,
                              body,
                              controlbar
                              # sidebar_fullCollapse = TRUE))
                ))
                        

server <- function(input, output) {
  output$scatter <- renderPlot({
    plot(iris$Petal.Length, iris$Petal.Width, pch = 21)
    cats <- levels(iris$Species)
    cols <- c("red", "blue", "yellow2")
    ind <- lapply(cats, function(z)
      which(iris$Species == z))
    for (i in seq(cats)) {
      points(iris$Petal.Length[ind[[i]]],
             iris$Petal.Width[ind[[i]]],
             pch = 19,
             col = cols[i])
    }
  })
}

shinyApp(ui, server)
> sessionInfo()
R Under development (unstable) (2020-10-17 r79346)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinyEffects_0.1.0       styler_1.4.1            
[3] shinyAce_0.4.1           shinyWidgets_0.6.0      
[5] shinyjqui_0.4.0          shiny_1.6.0             
[7] shinydashboardPlus_2.0.0 shinydashboard_0.7.1 
lmsimp
  • 882
  • 7
  • 22

0 Answers0