Skip to content

Commit da45eb5

Browse files
bborgesrdmpe
authored andcommitted
added collapsed argument to dashboardSidebar() that allows it to start off collapsed (fixes #73) (#186)
1 parent a3a0a2e commit da45eb5

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
shinydashboard 0.5.3.9000
22
=========================
33

4+
* Fixed [#73](https://github.com/rstudio/shinydashboard/issues/73): add `collapsed` argument to `dashboardSidebar()`, which allows it to start off collapsed. ([#186](https://github.com/rstudio/shinydashboard/pull/186))
5+
46
* Fixed [#62](https://github.com/rstudio/shinydashboard/issues/62): make images resize when the sidebar collapses/expands. [#185](https://github.com/rstudio/shinydashboard/pull/185)
57

68
* Addressed [#178](https://github.com/rstudio/shinydashboard/issues/178): switch from `npm` to `yarn`. Also upgraded all yarn packages to the `latest` tag (all major changes). [#184](https://github.com/rstudio/shinydashboard/pull/184)

R/dashboardPage.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,16 @@ dashboardPage <- function(header, sidebar, body, title = NULL,
6161
body
6262
)
6363

64+
# if the sidebar has the class "start-collapsed", it means that the user set
65+
# the `collapsed` argument of `dashboardSidebar` to TRUE
66+
collapsed <- "start-collapsed" %in% strsplit(sidebar$attribs$class, " ")[[1]]
67+
6468
addDeps(
65-
tags$body(class = paste0("skin-", skin), style = "min-height: 611px;",
69+
tags$body(
70+
# the "sidebar-collapse" class on the body means that the sidebar should
71+
# the collapsed (AdminLTE code)
72+
class = paste0("skin-", skin, if (collapsed) " sidebar-collapse"),
73+
style = "min-height: 611px;",
6674
shiny::bootstrapPage(content, title = title)
6775
)
6876
)

R/dashboardSidebar.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' @param width The width of the sidebar. This must either be a number which
99
#' specifies the width in pixels, or a string that specifies the width in CSS
1010
#' units.
11+
#' @param collapsed If \code{TRUE}, the sidebar will be collapsed on app startup.
1112
#'
1213
#' @seealso \code{\link{sidebarMenu}}
1314
#'
@@ -59,7 +60,7 @@
5960
#' )
6061
#' }
6162
#' @export
62-
dashboardSidebar <- function(..., disable = FALSE, width = NULL) {
63+
dashboardSidebar <- function(..., disable = FALSE, width = NULL, collapsed = FALSE) {
6364
width <- validateCssUnit(width)
6465

6566
# Set up custom CSS for custom width
@@ -113,11 +114,15 @@ dashboardSidebar <- function(..., disable = FALSE, width = NULL) {
113114
'))))
114115
}
115116

116-
tags$aside(class = "main-sidebar",
117+
# The expanded/collapsed state of the sidebar is actually set by adding a
118+
# class to the body (not to the sidebar). However, it makes sense for the
119+
# `collapsed` argument to belong in this function. So this information is
120+
# just passed through (also as a class) to the `dashboardPage()` function
121+
tags$aside(class = paste("main-sidebar", if (collapsed) "start-collapsed"),
117122
custom_css,
118123
tags$section(
119124
class = "sidebar",
120-
`data-disable` = if(disable) 1 else NULL,
125+
`data-disable` = if (disable) 1 else NULL,
121126
list(...)
122127
)
123128
)

man/dashboardSidebar.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)