diff --git a/R/boxes.R b/R/boxes.R index 4f287ec9..90e0be8a 100644 --- a/R/boxes.R +++ b/R/boxes.R @@ -58,6 +58,8 @@ 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 progressValue A numeric value to display in the progress bar. +#' Must be between 0 and 100. #' #' @family boxes #' @seealso \code{\link{box}} for usage examples. @@ -65,7 +67,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, progressValue = NULL) { validateColor(color) tagAssert(icon, type = "i") @@ -83,7 +85,8 @@ infoBox <- function(title, value = NULL, subtitle = NULL, div(class = "info-box-content", span(class = "info-box-text", title), if (!is.null(value)) span(class = "info-box-number", value), - if (!is.null(subtitle)) p(subtitle) + if (!is.null(progressValue)) div(class = "progress", progressValue), + if (!is.null(subtitle)) span(class = "progress-description", subtitle) ) ) diff --git a/man/infoBox.Rd b/man/infoBox.Rd index e2695477..36f363a2 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, progressValue = NULL) } \arguments{ \item{title}{Title text.} @@ -33,6 +33,9 @@ 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{progressValue}{A numeric value to display in the progress bar. +Must be between 0 and 100.} } \description{ An info box displays a large icon on the left side, and a title, value diff --git a/tests-manual/box.R b/tests-manual/box.R index 53934085..fd9e567b 100644 --- a/tests-manual/box.R +++ b/tests-manual/box.R @@ -1,23 +1,25 @@ # A dashboard body with a row of infoBoxes and valueBoxes, and two rows of other boxes library(shiny) +library(shinydashboard) + body <- dashboardBody( - # infoBoxes + # infoBoxes -> first row fluidRow( infoBox( - "Orders", uiOutput("orderNum2"), "Subtitle", icon = icon("credit-card") + "Orders", uiOutput("orderNum2"), subtitle = "Test", icon = icon("credit-card"), + fill = TRUE, progressValue = uiOutput("progressBarValue") ), infoBox( - "Approval Rating", "60%", icon = icon("line-chart"), color = "green", - fill = TRUE + "Approval Rating", "60%", icon = icon("line-chart"), color = "green", fill = TRUE ), infoBox( "Progress", uiOutput("progress2"), icon = icon("users"), color = "purple" ) ), - # valueBoxes + # valueBoxes -> second row fluidRow( valueBox( uiOutput("orderNum"), "New Orders", icon = icon("credit-card"), @@ -90,6 +92,10 @@ server <- function(input, output) { paste0(input$progress, "%") }) + output$progressBarValue <- renderUI({ + div(class = "progress-bar", style = paste0("width: ", input$progress, "%; height: 2px;")) + }) + output$status <- renderText({ paste0("There are ", input$orders, " orders, and so the current progress is ", input$progress, "%.")