Skip to content

Commit

Permalink
added collapsed argument to dashboardSidebar() that allows it to st…
Browse files Browse the repository at this point in the history
…art off collapsed (fixes #73)
  • Loading branch information
bborgesr committed Feb 23, 2017
1 parent 7ae59f9 commit 21d8646
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
shinydashboard 0.5.3.9000
=========================

* 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))

* 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)

* 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)
Expand Down
10 changes: 9 additions & 1 deletion R/dashboardPage.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ dashboardPage <- function(header, sidebar, body, title = NULL,
body
)

# if the sidebar has the class "start-collapsed", it means that the user set
# the `collapsed` argument of `dashboardSidebar` to TRUE
collapsed <- "start-collapsed" %in% strsplit(sidebar$attribs$class, " ")[[1]]

addDeps(
tags$body(class = paste0("skin-", skin), style = "min-height: 611px;",
tags$body(
# the "sidebar-collapse" class on the body means that the sidebar should
# the collapsed (AdminLTE code)
class = paste0("skin-", skin, if (collapsed) " sidebar-collapse"),
style = "min-height: 611px;",
shiny::bootstrapPage(content, title = title)
)
)
Expand Down
11 changes: 8 additions & 3 deletions R/dashboardSidebar.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param width The width of the sidebar. This must either be a number which
#' specifies the width in pixels, or a string that specifies the width in CSS
#' units.
#' @param collapsed If \code{TRUE}, the sidebar will be collapsed on app startup.
#'
#' @seealso \code{\link{sidebarMenu}}
#'
Expand Down Expand Up @@ -59,7 +60,7 @@
#' )
#' }
#' @export
dashboardSidebar <- function(..., disable = FALSE, width = NULL) {
dashboardSidebar <- function(..., disable = FALSE, width = NULL, collapsed = FALSE) {
width <- validateCssUnit(width)

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

tags$aside(class = "main-sidebar",
# The expanded/collapsed state of the sidebar is actually set by adding a
# class to the body (not to the sidebar). However, it makes sense for the
# `collapsed` argument to belong in this function. So this information is
# just passed through (also as a class) to the `dashboardPage()` function
tags$aside(class = paste("main-sidebar", if (collapsed) "start-collapsed"),
custom_css,
tags$section(
class = "sidebar",
`data-disable` = if(disable) 1 else NULL,
`data-disable` = if (disable) 1 else NULL,
list(...)
)
)
Expand Down
4 changes: 3 additions & 1 deletion man/dashboardSidebar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 21d8646

Please sign in to comment.