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

[WIP] progress bar in infoBox #135

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
15 changes: 12 additions & 3 deletions R/boxes.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ valueBox <- function(value, subtitle, icon = NULL, color = "aqua", width = 4,

#' Create an info box for the main body of a dashboard.
#'
#' An info box displays a large icon on the left side, and a title, value
#' @description An info box displays a large icon on the left side, and a title, value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is unneeded.

#' (usually a number), and an optional smaller subtitle on the right side. Info
#' boxes are meant to be placed in the main body of a dashboard.
#'
Expand All @@ -58,14 +58,18 @@ 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 progressBar If \code{FALSE} (the default), does not add a progress bar
#' below the \code{value} parameter.
#' @param progressBarValue A numeric value to display in the progress bar. Must
#' be between zero percent and 100 percent (without the percent sign). See examples.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just say, "Must be between 0 and 100."

#'
#' @family boxes
#' @seealso \code{\link{box}} for usage examples.
#'
#' @export
infoBox <- function(title, value = NULL, subtitle = NULL,
icon = shiny::icon("bar-chart"), color = "aqua", width = 4, href = NULL,
fill = FALSE) {
fill = FALSE, progressBar = FALSE, progressBarValue = NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better as just a single argument, like progressValue.


validateColor(color)
tagAssert(icon, type = "i")
Expand All @@ -83,7 +87,12 @@ 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 (progressBar) div(class = "progress", div(class = "progress-bar", style = progressBarValue)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous comments?

# if (progressBar) div(class = "progress", div(class = "progress-bar", style =
# paste0("width: ", progressBarValue, "%; height: 2px;"))),

if (progressBar) div(class = "progress", progressBarValue),
if (!is.null(subtitle)) span(class = "progress-description", subtitle)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

span(class = "progress-description", subtitle) now uses CSS from AdminLTE which makes sure it behave correctly due to margins.

)
)

Expand Down
9 changes: 8 additions & 1 deletion man/infoBox.Rd

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

23 changes: 18 additions & 5 deletions tests-manual/box.R
Original file line number Diff line number Diff line change
@@ -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"),
progressBar = T, fill = T, progressBarValue = 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"),
Expand Down Expand Up @@ -90,6 +92,17 @@ server <- function(input, output) {
paste0(input$progress, "%")
})

output$progressBarValue <- renderUI({
# input$progress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comments?

# numberPercent <- paste0("width: ", input$progress, "%")
# div(class = "progress", div(class = "progress-bar", style = numberPercent))

div(class = "progress-bar", style = paste0("width: ", input$progress, "%; height: 2px;"))
# tagList(style = paste0("width: ", input$progress, "%; height: 2px;"))

# paste0("width: ", input$progress, "%; height: 2px;")
})

output$status <- renderText({
paste0("There are ", input$orders,
" orders, and so the current progress is ", input$progress, "%.")
Expand Down