Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collapsed argument to dashboardSidebar() #186

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.