Skip to content
Open
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 .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
man-roxygen
Expand Down
2 changes: 2 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source("renv/activate.R")
require("devtools")
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Imports:
htmltools
URL: https://ebailey78.github.io/shinyBS
BugReports: https://github.com/ebailey78/shinyBS/issues
License: GPL-3
License: GPL-3
RoxygenNote: 7.1.1
6 changes: 5 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Generated by roxygen2 (4.1.0): do not edit by hand
# Generated by roxygen2: do not edit by hand

export(addPopover)
export(addTooltip)
export(bsAlert)
export(bsButton)
export(bsCollapse)
export(bsCollapseButton)
export(bsCollapseLink)
export(bsCollapsePanel)
export(bsExample)
export(bsModal)
Expand All @@ -21,3 +23,5 @@ export(toggleModal)
export(updateButton)
export(updateCollapse)
export(updateTypeahead)
importFrom(shiny,actionButton)
importFrom(shiny,actionLink)
63 changes: 63 additions & 0 deletions R/bsCollapseButton.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#' Create a button or link that toggles the state of a
#' \code{\link{bsCollapsePanel}}.
#'
#' @inheritParams shiny::actionButton
#'
#' @templateVar item_name bsCollapseButton
#' @templateVar family_name Collapses
#' @template item_details
#' @template footer
#'
#' @param target HTML id of object to be toggled
#' @param parent \bold{Optional} HTML id of parent container
#'
#' @importFrom shiny actionButton
#' @importFrom shiny actionLink
#'
NULL

#'
#' @describeIn bsCollapseButton Create an \code{\link[shiny]{actionLink}}
#' that will toggle the collapsed state of a
#' \code{\link{bsCollapsePanel}} when clicked.
#' @export
bsCollapseButton <- function(inputId, label, target, parent=NULL, icon=NULL, width=NULL, ...)
{
target = paste0("#", target)
if(!is.null(parent)) parent <- paste0("#", parent)

actionButton(inputId,
label,
icon=icon,
width=width,
...,
"data-toggle"="collapse",
"data-target"=target,
"data-parent"=parent
)
}

#' @describeIn bsCollapseButton Create an \code{\link[shiny]{actionLink}}
#' that will toggle the collapsed state of a
#' \code{\link{bsCollapsePanel}} when clicked.
#' @export
bsCollapseLink <- function(inputId, label, target, parent=NULL, icon=NULL, width=NULL, ...)
{

if(!is.null(parent))
parent <- paste0("#", parent)

tmp <- actionLink(inputId,
label,
icon=icon,
width=width,
...,
"data-toggle"="collapse",
"data-parent"=parent
)

tmp$attribs$href=paste0('#', target)

tmp
}

7 changes: 5 additions & 2 deletions R/bsCollapsePanel.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#'@param title The title to display at the top of the panel.
#'@param \dots UI elements to include within the panel.
#'@param id \bold{Optional} HTML id. Auto-generated if missing.
#'@param value \bold{Optional} The value to return when this panel is open. Defaults to \code{title}.
#'@param style \bold{Optional} A Bootstrap style to apply to the panel. (\code{primary}, \code{danger}, \code{warning}, \code{info}, or \code{success})
#'
Expand All @@ -12,11 +13,13 @@
#'@template item_details
#'@template footer
#'@export
bsCollapsePanel <- function(title, ..., value = title, style = NULL) {
bsCollapsePanel <- function(title, ..., id, value = title, style = NULL) {

content <- list(...)

id <- paste0("cpanel", sprintf("%07i", as.integer(stats::runif(1, 1, 1000000))))
if(missing(id))
id <- paste0("cpanel", sprintf("%07i", as.integer(stats::runif(1, 1, 1000000))))

if(is.null(value)) {
value = title
}
Expand Down
85 changes: 67 additions & 18 deletions inst/examples/Collapses/ui.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,70 @@
library(shiny)
library(shinyBS)
fluidPage(
sidebarLayout(
sidebarPanel(HTML("This button will open Panel 1 using <code>updateCollapse</code>."),
actionButton("p1Button", "Push Me!"),
selectInput("styleSelect", "Select style for Panel 1",
c("default", "primary", "danger", "warning", "info", "success"))
),
mainPanel(
bsCollapse(id = "collapseExample", open = "Panel 2",
bsCollapsePanel("Panel 1", "This is a panel with just text ",
"and has the default style. You can change the style in ",
"the sidebar.", style = "info"),
bsCollapsePanel("Panel 2", "This panel has a generic plot. ",
"and a 'success' style.", plotOutput("genericPlot"), style = "success")
)
)
fluidPage(sidebarLayout(
sidebarPanel(
tags$ul(
tags$li(
HTML(
"This button will open Panel 1 using",
"<code>updateCollapse</code>, but won't close it."
),
actionButton("p1Button", "Push me!")
),
tags$li(
HTML(
"This button will toggle Panel 1 ",
"<strong>without</strong>",
" using <code>updateCollapse</code>"
),
bsCollapseButton(
"p2Button",
"Or push me!",
"panel1",
class = "btn-primary"
)
),
tags$li(
HTML(
"This link will toggle Panel 2 ",
"<strong>without</strong>",
" using <code>updateCollapse</code>"
),
bsCollapseLink(
"p2Button",
"Or click this link!",
"panel2",
parent = "collapseExample"
)
)
),
selectInput(
"styleSelect",
"Select style for Panel 1",
c("default", "primary", "danger",
"warning", "info", "success")
)
),
mainPanel(
bsCollapse(
id = "collapseExample",
open = "Panel 2",
# multiple = TRUE,
bsCollapsePanel(
"Panel 1",
id = "panel1",
"This is a panel with just text ",
"and has the default style. You can change the style in ",
"the sidebar.",
style = "info"
),
bsCollapsePanel(
"Panel 2",
id = "panel2",
"This panel has a generic plot. ",
"and a 'success' style.",
plotOutput("genericPlot"),
style = "success"
)
)
)
)

))
40 changes: 22 additions & 18 deletions man/Alerts.Rd

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

Loading