Skip to content

Instantly share code, notes, and snippets.

@artemklevtsov
Last active January 29, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artemklevtsov/d280c4343b052c2aaaef to your computer and use it in GitHub Desktop.
Save artemklevtsov/d280c4343b052c2aaaef to your computer and use it in GitHub Desktop.
Bootstrap progress bar widget for the Shiny framework. Source: http://getbootstrap.com/components/#progress
prgoressBar <- function(value = 0, label = FALSE, color = "aqua", size = NULL,
striped = FALSE, active = FALSE, vertical = FALSE) {
stopifnot(is.numeric(value))
if (value < 0 || value > 100)
stop("'value' should be in the range from 0 to 100", call. = FALSE)
if (!(color %in% shinydashboard:::validColors || color %in% shinydashboard:::validStatuses))
stop("'color' should be a valid status or color.", call. = FALSE)
if (!is.null(size))
size <- match.arg(size, c("sm", "xs", "xxs"))
text_value <- paste0(value, "%")
if (vertical)
style <- htmltools::css(height = text_value, `min-height` = "2em")
else
style <- htmltools::css(width = text_value, `min-width` = "2em")
htmltools::tags$div(
class = "progress",
class = if (!is.null(size)) paste0("progress-", size),
class = if (vertical) "vertical",
class = if (active) "active",
htmltools::tags$div(
class = "progress-bar",
class = paste0("progress-bar-", color),
class = if (striped) "progress-bar-striped",
style = style,
role = "progressbar",
`aria-valuenow` = value,
`aria-valuemin` = 0,
`aria-valuemax` = 100,
htmltools::tags$span(class = if (!label) "sr-only", text_value)
)
)
}
@artemklevtsov
Copy link
Author

Examples:

prgoressBar(100)
#> <div class="progress">
#>   <div class="progress-bar progress-bar-aqua" style="width: 1%; min-width: 2em;" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
#>     <span class="sr-only">100%</span>
#>   </div>
#> </div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment