diff --git a/R/boxes.R b/R/boxes.R index 4f287ec9..b130c903 100644 --- a/R/boxes.R +++ b/R/boxes.R @@ -11,13 +11,14 @@ #' @param color A color for the box. Valid colors are listed in #' \link{validColors}. #' @param href An optional URL to link to. +#' @param id An optional id for the element #' #' @family boxes #' @seealso \code{\link{box}} for usage examples. #' #' @export valueBox <- function(value, subtitle, icon = NULL, color = "aqua", width = 4, - href = NULL) + href = NULL, id = NULL) { validateColor(color) if (!is.null(icon)) tagAssert(icon, type = "i") @@ -34,6 +35,7 @@ valueBox <- function(value, subtitle, icon = NULL, color = "aqua", width = 4, boxContent <- a(href = href, boxContent) div(class = if (!is.null(width)) paste0("col-sm-", width), + id = id, boxContent ) } @@ -58,6 +60,7 @@ valueBox <- function(value, subtitle, icon = NULL, color = "aqua", width = 4, #' content; the icon will use the same color with a slightly darkened #' background. #' @param href An optional URL to link to. +#' @param id An optional id for the element #' #' @family boxes #' @seealso \code{\link{box}} for usage examples. @@ -65,7 +68,7 @@ valueBox <- function(value, subtitle, icon = NULL, color = "aqua", width = 4, #' @export infoBox <- function(title, value = NULL, subtitle = NULL, icon = shiny::icon("bar-chart"), color = "aqua", width = 4, href = NULL, - fill = FALSE) { + fill = FALSE, id = NULL) { validateColor(color) tagAssert(icon, type = "i") @@ -91,6 +94,7 @@ infoBox <- function(title, value = NULL, subtitle = NULL, boxContent <- a(href = href, boxContent) div(class = if (!is.null(width)) paste0("col-sm-", width), + id = id, boxContent ) } @@ -119,6 +123,7 @@ infoBox <- function(title, value = NULL, subtitle = NULL, #' the user to collapse the box. #' @param collapsed If TRUE, start collapsed. This must be used with #' \code{collapsible=TRUE}. +#' @param id An optional id for the element #' @param ... Contents of the box. #' #' @family boxes @@ -250,7 +255,7 @@ infoBox <- function(title, value = NULL, subtitle = NULL, #' @export box <- function(..., title = NULL, footer = NULL, status = NULL, solidHeader = FALSE, background = NULL, width = 6, - height = NULL, collapsible = FALSE, collapsed = FALSE) { + height = NULL, collapsible = FALSE, collapsed = FALSE, id = NULL) { boxClass <- "box" if (solidHeader || !is.null(background)) { @@ -301,6 +306,7 @@ box <- function(..., title = NULL, footer = NULL, status = NULL, } div(class = if (!is.null(width)) paste0("col-sm-", width), + id = id, div(class = boxClass, style = if (!is.null(style)) style, headerTag, diff --git a/R/dashboardSidebar.R b/R/dashboardSidebar.R index 4cb17764..71ac05e8 100644 --- a/R/dashboardSidebar.R +++ b/R/dashboardSidebar.R @@ -364,7 +364,7 @@ sidebarMenu <- function(..., id = NULL, .list = NULL) { #' @rdname sidebarMenu #' @export menuItem <- function(text, ..., icon = NULL, badgeLabel = NULL, badgeColor = "green", - tabName = NULL, href = NULL, newtab = TRUE, selected = NULL, + tabName = NULL, href = NULL, newtab = TRUE, selected = NULL, id = NULL, expandedName = as.character(gsub("[[:space:]]", "", text)), startExpanded = FALSE) { subItems <- list(...) @@ -407,7 +407,7 @@ menuItem <- function(text, ..., icon = NULL, badgeLabel = NULL, badgeColor = "gr # If no subitems, return a pretty simple tag object if (length(subItems) == 0) { return( - tags$li( + tags$li(id = id, a(href = href, `data-toggle` = if (isTabItem) "tab", `data-value` = if (!is.null(tabName)) tabName, @@ -433,7 +433,7 @@ menuItem <- function(text, ..., icon = NULL, badgeLabel = NULL, badgeColor = "gr # this menuItem's `expandedName`` isExpanded <- nzchar(dataExpanded) && (dataExpanded == expandedName) - tags$li(class = "treeview", + tags$li(class = "treeview", id = id, a(href = href, icon, span(text), @@ -453,7 +453,7 @@ menuItem <- function(text, ..., icon = NULL, badgeLabel = NULL, badgeColor = "gr #' @rdname sidebarMenu #' @export menuSubItem <- function(text, tabName = NULL, href = NULL, newtab = TRUE, - icon = shiny::icon("angle-double-right"), selected = NULL) + icon = shiny::icon("angle-double-right"), selected = NULL, id = NULL) { if (!is.null(href) && !is.null(tabName)) { @@ -476,7 +476,7 @@ menuSubItem <- function(text, tabName = NULL, href = NULL, newtab = TRUE, } - tags$li( + tags$li( id = id, a(href = href, `data-toggle` = if (isTabItem) "tab", `data-value` = if (!is.null(tabName)) tabName, diff --git a/man/box.Rd b/man/box.Rd index d1064b1c..63a33774 100644 --- a/man/box.Rd +++ b/man/box.Rd @@ -6,7 +6,7 @@ \usage{ box(..., title = NULL, footer = NULL, status = NULL, solidHeader = FALSE, background = NULL, width = 6, height = NULL, - collapsible = FALSE, collapsed = FALSE) + collapsible = FALSE, collapsed = FALSE, id = NULL) } \arguments{ \item{...}{Contents of the box.} @@ -38,6 +38,8 @@ the user to collapse the box.} \item{collapsed}{If TRUE, start collapsed. This must be used with \code{collapsible=TRUE}.} + +\item{id}{An optional id for the element} } \description{ Boxes can be used to hold content in the main body of a dashboard. diff --git a/man/infoBox.Rd b/man/infoBox.Rd index fcbd2666..fb1488e7 100644 --- a/man/infoBox.Rd +++ b/man/infoBox.Rd @@ -6,7 +6,7 @@ \usage{ infoBox(title, value = NULL, subtitle = NULL, icon = shiny::icon("bar-chart"), color = "aqua", width = 4, - href = NULL, fill = FALSE) + href = NULL, fill = FALSE, id = NULL) } \arguments{ \item{title}{Title text.} @@ -33,6 +33,8 @@ content, and the \code{color} argument for the background of the icon. If \code{TRUE}, use the \code{color} argument for the background of the content; the icon will use the same color with a slightly darkened background.} + +\item{id}{An optional id for the element} } \description{ An info box displays a large icon on the left side, and a title, value diff --git a/man/sidebarMenu.Rd b/man/sidebarMenu.Rd index 4fac78b0..90a30abb 100644 --- a/man/sidebarMenu.Rd +++ b/man/sidebarMenu.Rd @@ -10,11 +10,11 @@ sidebarMenu(..., id = NULL, .list = NULL) menuItem(text, ..., icon = NULL, badgeLabel = NULL, badgeColor = "green", tabName = NULL, href = NULL, newtab = TRUE, selected = NULL, - expandedName = as.character(gsub("[[:space:]]", "", text)), + id = NULL, expandedName = as.character(gsub("[[:space:]]", "", text)), startExpanded = FALSE) menuSubItem(text, tabName = NULL, href = NULL, newtab = TRUE, - icon = shiny::icon("angle-double-right"), selected = NULL) + icon = shiny::icon("angle-double-right"), selected = NULL, id = NULL) } \arguments{ \item{...}{For menu items, this may consist of \code{\link{menuSubItem}}s.} diff --git a/man/valueBox.Rd b/man/valueBox.Rd index 1e97c79b..8ad7957d 100644 --- a/man/valueBox.Rd +++ b/man/valueBox.Rd @@ -5,7 +5,7 @@ \title{Create a value box for the main body of a dashboard.} \usage{ valueBox(value, subtitle, icon = NULL, color = "aqua", width = 4, - href = NULL) + href = NULL, id = NULL) } \arguments{ \item{value}{The value to display in the box. Usually a number or short text.} @@ -24,6 +24,8 @@ layouts, use \code{NULL} for the width; the width is set by the column that contains the box.} \item{href}{An optional URL to link to.} + +\item{id}{An optional id for the element} } \description{ A value box displays a value (usually a number) in large text, with a smaller diff --git a/tests-manual/dashboardSidebar.R b/tests-manual/dashboardSidebar.R index e8bcf179..c0acab60 100644 --- a/tests-manual/dashboardSidebar.R +++ b/tests-manual/dashboardSidebar.R @@ -16,20 +16,23 @@ sidebar <- dashboardSidebar( menuItem( "Dashboard", tabName = "dashboard", - icon = icon("dashboard") + icon = icon("dashboard"), + id = "dashboardmenuitem" ), menuItem( "Widgets", icon = icon("th"), tabName = "widgets", badgeLabel = "new", - badgeColor = "green" + badgeColor = "green", + id = "widgetsmenuitem" ), menuItem( "Charts", icon = icon("bar-chart-o"), - menuSubItem("Sub-item 1", tabName = "subitem1"), - menuSubItem("Sub-item 2", tabName = "subitem2") + menuSubItem("Sub-item 1", tabName = "subitem1", id = "subitem1menuitem"), + menuSubItem("Sub-item 2", tabName = "subitem2", id = "subitem2menuitem"), + id = "chartsmenuitem" ) ) ) diff --git a/tests-manual/renderMenu.R b/tests-manual/renderMenu.R index 5bc5b227..8aa7e341 100644 --- a/tests-manual/renderMenu.R +++ b/tests-manual/renderMenu.R @@ -12,7 +12,7 @@ ui <- dashboardPage( server <- function(input, output) { output$menu <- renderMenu({ sidebarMenu( - menuItem("Menu item", icon = icon("calendar")) + menuItem("Menu item", icon = icon("calendar"), id = "aaa") ) }) }