Skip to content

Progress-bar function #119

@artemklevtsov

Description

@artemklevtsov

According this: https://almsaeedstudio.com/themes/AdminLTE/pages/UI/general.html

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")
    tags$div(
        class = "progress",
        class = if (!is.null(size)) paste0("progress-", size),
        class = if (vertical) "vertical",
        class = if (active) "active",
        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,
            tags$span(class = if (!label) "sr-only", text_value)
        )
    )
}

progressGroup <- function(text, value, min = 0, max = value, color = "aqua") {
    stopifnot(is.character(text))
    stopifnot(is.numeric(value))
    if (value < min || value > max)
        stop(sprintf("'value' should be in the range from %d to %d.", min, max), call. = FALSE)
    tags$div(
        class = "progress-group",
        tags$span(class = "progress-text", text),
        tags$span(class = "progress-number", sprintf("%d / %d", value, max)),
        prgoressBar(round(value / max * 100), color = color, size = "sm")
    )
}

Output with default params:

prgoressBar(10)
#> <div class="progress">
#>   <div aria-valuemax="100" aria-valuemin="0" aria-valuenow="10" class="progress-bar progress-bar-aqua" role="progressbar" style="width:10%;min-width:2em;">
#>     <span class="sr-only">10%</span>
#>   </div>
#> </div> 
progressGroup("Text", 150, 0, 300)
#> <div class="progress-group">
#>   <span class="progress-text">Text</span>
#>   <span class="progress-number">150 / 300</span>
#>   <div class="progress progress-sm">
#>     <div aria-valuemax="100" aria-valuemin="0" aria-valuenow="50" class="progress-bar progress-bar-aqua" role="progressbar" style="width:50%;min-width:2em;">
#>       <span class="sr-only">50%</span>
#>     </div>
#>   </div>
#> </div> 

To reproduce examples from the AdminLTE docs:

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(disable = TRUE),
    dashboardBody(
        h2("Progress Bars"),
        fluidRow(
            box(title = "Progress Bars Different Sizes",
                p("Normal"),
                prgoressBar(40, color = "primary", striped = TRUE),
                p("Small"),
                prgoressBar(20, color = "green", striped = TRUE, active = TRUE, size = "sm"),
                p("Extra small"),
                prgoressBar(60, color = "yellow", striped = TRUE, size = "xs"),
                p("Extra extra small"),
                prgoressBar(60, color = "red", striped = TRUE, size = "xxs")
            ),
            box(title = "Progress bars",
                prgoressBar(40, color = "green"),
                prgoressBar(20, color = "aqua"),
                prgoressBar(60, color = "yellow"),
                prgoressBar(80, color = "red")
            )
        ),
        fluidRow(
            box(title = "Progress Bars Different Sizes",
                class = "text-center",
                prgoressBar(40, color = "primary", striped = TRUE, active = TRUE, vertical = TRUE),
                prgoressBar(100, color = "green", vertical = TRUE, size = "sm"),
                prgoressBar(50, color = "yellow", striped = TRUE, vertical = TRUE, size = "xs"),
                prgoressBar(50, color = "aqua", vertical = TRUE, size = "xxs")
            ),
            box(title = "Vertical Progress bars",
                class = "text-center",
                prgoressBar(40, color = "green", vertical = TRUE),
                prgoressBar(20, color = "aqua", vertical = TRUE),
                prgoressBar(60, color = "yellow", vertical = TRUE),
                prgoressBar(80, color = "red", vertical = TRUE)
            )
        ),
        fluidRow(
            box(title = "Progress Groups",
                p(strong("Goal Completion"), class = "text-center"),
                progressGroup("Add Products to Cart", 160, 0, 200),
                progressGroup("Complete Purchase", 310, 0, 400, color = "red"),
                progressGroup("Visit Premium Page", 480, 0, 800, color = "green"),
                progressGroup("Send Inquiries", 250, 0, 500, color = "yellow")
            )
        )

    )
)

server <- function(input, output) { }

shinyApp(ui, server)

2016-01-30 16 10 32

Also may be helpful to add an appropriate render and output functions.

~~
wbr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions