-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
488 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Generated by roxygen2 (4.1.0): do not edit by hand | ||
|
||
export(bsAlert) | ||
export(bsCollapse) | ||
export(bsCollapsePanel) | ||
export(closeAlert) | ||
export(createAlert) | ||
export(updateCollapse) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#' Collapse Panels | ||
#' | ||
#' Collapse panels allow you to reduce clutter in your Shiny app by making | ||
#' panels of information that open and close with a user's click. Any type of | ||
#' content can go in a collapse panel. Standard Bootstrap styling options are | ||
#' available. | ||
#' | ||
#'@section Components: | ||
#' \describe{ | ||
#' \item{\code{\link{bsCollapse}}}{A container for holder the individual panels created by \code{\link{bsCollapsePanel}}.} | ||
#' \item{\code{\link{bsCollapsePanel}}}{Creates an individual Collapse Panel that resides within a \code{\link{bsCollapse}}.} | ||
#' \item{\code{\link{updateCollapse}}}{Used within your server logic to open/close collapse panels or change their style.} | ||
#'} | ||
#'@family Collapses | ||
#'@name Collapses | ||
#'@template group_footer | ||
NULL | ||
|
||
#' bsCollapse | ||
#' | ||
#' Create a collapse that contains \code{\link{bsCollapsePanel}} elements. | ||
#' See \code{\link{Collapses}} | ||
#' | ||
#'@param id If provided, you can use input$id in your server script to open or | ||
#' close \code{bsCollapsePanels} within the \code{bsCollapse}. | ||
#'@param multiple \code{logical} indication whether multiple \code{bsCollapsePanels} | ||
#' within this \code{bsCollapse} can be open at once. | ||
#'@param open The \code{value} (or, if none was supplied, the title) of the | ||
#' \code{bsCollapsePanel} that should be open. If \code{multiple = TRUE}, then | ||
#' this can be a vector of \code{value}s or \code{title}s. | ||
#'@param \dots \code{\link{bsCollapsePanel}} elements to include in the \code{bsCollapse}. | ||
#'@family Collapses | ||
#'@template footer | ||
#'@export | ||
bsCollapse <- function(..., id = NULL, multiple = FALSE, open = NULL) { | ||
if(is.null(id)) id = paste0("collapse", sprintf("%07i", as.integer(stats::runif(1, 1, 1000000)))) | ||
|
||
if(!multiple & length(open) > 1) { | ||
open <- open[1] | ||
} | ||
|
||
panels <- list(...) | ||
panels <<- panels | ||
for(i in seq(length(panels))) { | ||
if(getAttribs(panels[[i]])$value %in% open) { | ||
panels[[i]]$children[[2]] <- addClass(panels[[i]]$children[[2]], "in") | ||
} | ||
if(!multiple) { | ||
panels[[i]]$children[[1]]$children[[1]]$children[[1]] <- addAttribs(panels[[i]]$children[[1]]$children[[1]]$children[[1]], 'data-parent' = paste0("#", id)) | ||
} | ||
} | ||
|
||
bsTag <- tags$div(class = "panel-group sbs-panel-group", id=id, role = "tablist", panels) | ||
htmltools::attachDependencies(bsTag, shinyBSDep) | ||
|
||
} | ||
|
||
#' bsCollapsePanel | ||
#' | ||
#' Create a collapse panel that can be included within a \code{\link{bsCollapse}} | ||
#' See \code{\link{Collapses}} | ||
#' | ||
#'@param title The title to display at the top of the \code{bsCollapsePanel} | ||
#'@param value The value that should be returned to the server when this | ||
#' \code{bsCollapsePanel} is open. | ||
#'@param \dots UI elements to include within the collapse panel | ||
#'@inheritParams Alerts | ||
#'@family Collapses | ||
#'@template footer | ||
#'@export | ||
bsCollapsePanel <- function(title, ..., value = title, style = NULL) { | ||
|
||
content <- list(...) | ||
|
||
id <- paste0("cpanel", sprintf("%07i", as.integer(stats::runif(1, 1, 1000000)))) | ||
if(is.null(value)) { | ||
value = title | ||
} | ||
if(is.null(style)) { | ||
style = "default" | ||
} | ||
|
||
bsTag <- tags$div(class = paste0("panel panel-", style), value = value, | ||
tags$div(class = "panel-heading", role = "tab", id = paste0("heading_", id), | ||
tags$h4(class = "panel-title", | ||
tags$a("data-toggle" = "collapse", href = paste0("#", id), title) | ||
) | ||
), | ||
tags$div(id = id, class = "panel-collapse collapse", role = "tabpanel", | ||
tags$div(class = "panel-body", content) | ||
) | ||
) | ||
|
||
htmltools::attachDependencies(bsTag, shinyBSDep) | ||
|
||
} | ||
|
||
#' updateCollapse | ||
#' | ||
#' Open or close collapse panels or change their styles. See \code{\link{Collapses}} | ||
#' | ||
#'@param id The id of the \code{\link{bsCollapse}} object you want to change. | ||
#'@param open A vector of \code{value} (or \code{title} if no \code{value} was provided) | ||
#'of the \code{\link{bsCollapsePanel}} elements you want to open. | ||
#'@param close A vector of \code{value} (or \code{title} if no \code{value} was provided) | ||
#'of the \code{\link{bsCollapsePanel}} elements you want to close. | ||
#'@param style A named list of Bootstrap styles (danger, info, warning, success, default). | ||
#'The names should correspond the the \code{value} of the \code{\link{bsCollapsePanel}} you | ||
#'want to change. | ||
#'@inheritParams Alerts | ||
#'@family Collapses | ||
#'@template footer | ||
#'@export | ||
updateCollapse <- function(session, id, open = NULL, close = NULL, style = NULL) { | ||
|
||
data <- dropNulls(list(open = open, close = close, style = style)) | ||
session$sendInputMessage(id, data) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
.onAttach <- function(...) { | ||
|
||
# Create link to javascript and css files for package | ||
shiny::addResourcePath("sbs", system.file("www", package="shinyBS")) | ||
|
||
} | ||
|
||
shinyBSDep <- htmltools::htmlDependency("shinyBS", packageVersion("shinyBS"), src = c("href" = "sbs"), script = "shinyBS.js", stylesheet = "shinyBS.css") | ||
|
||
# Wrapper to add the appropriate singletons to the head of the shiny app | ||
sbsHead <- function(...) { | ||
|
||
tagList(singleton(tags$head(tags$script(src = "sbs/shinyBS.js"), | ||
tags$link(rel = "stylesheet", type = "text/css", href = "sbs/shinyBS.css"))), | ||
... | ||
) | ||
} | ||
|
||
# Copy of dropNulls function for shiny to avoid using shiny:::dropNulls | ||
dropNulls <- function(x) { | ||
x[!vapply(x, is.null, FUN.VALUE = logical(1))] | ||
} | ||
|
||
# Takes a tag and removes any classes in the remove argument | ||
removeClass <- function(tag, remove) { | ||
|
||
if(length(remove) == 1) remove <- strsplit(remove, " ", fixed = TRUE)[[1]] | ||
class <- strsplit(tag$attribs$class, " ", fixed = TRUE)[[1]] | ||
class <- class[!(class %in% remove)] | ||
tag$attribs$class <- paste(class, collapse = " ") | ||
|
||
return(tag) | ||
|
||
} | ||
|
||
addClass <- function(tag, add) { | ||
tag$attribs$class <- paste(tag$attribs$class, add) | ||
return(tag) | ||
} | ||
|
||
addAttribs <- function(tag, ...) { | ||
a <- list(...) | ||
for(i in seq(length(a))) { | ||
tag$attribs[names(a)[i]] = a[[i]] | ||
} | ||
return(tag) | ||
} | ||
|
||
removeAttribs <- function(tag, ...) { | ||
a <- list(...) | ||
for(i in seq(length(a))) { | ||
tags$attribs[a[[i]]] = NULL | ||
} | ||
return(tag) | ||
} | ||
|
||
getAttribs <- function(tag) { | ||
tag$attribs | ||
} | ||
|
||
inputCheck <- function(..., valid, stop.func = FALSE) { | ||
|
||
v <- list(...)[1] | ||
|
||
if(!(v %in% valid)) { | ||
|
||
n <- names(list(...))[1] | ||
caller <- deparse(sys.call(-1)[1]) | ||
msg <- paste0("Invalid '", n, "' argument in ", caller, ": ", v) | ||
if(stop.func) { | ||
stop(msg, call. = FALSE) | ||
} else { | ||
warning(msg, call. = FALSE) | ||
} | ||
|
||
return(FALSE) | ||
|
||
} else { | ||
|
||
return(TRUE) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.