闪亮:如何在闪亮的应用程序中添加响应栏

问题描述:

我正在构建追踪捐赠数量的闪亮应用程序。有没有这种功能可以创建一个闪亮的反应棒?如果没有,是否可以在HTML,CSS,JavaScript中做到这一点?闪亮:如何在闪亮的应用程序中添加响应栏

我想是这样创造的东西:

enter image description here

+1

这是可能的,只要你有反应的数据集!示例代码将是有用的! –

+0

@Malvina_a我已经有了一个被动数据集。我的问题是如何通过使用闪亮的功能,html,css等来创建类似上面的图片。 – Oleole

+1

我已经理解了这个问题,但无论如何,创建具有示例数据的示例应用程序总是很好,所以有人希望帮助你,可以很容易地做到这一点... –

我对你有两种解决方案:

(1)我可以推荐你使用gaugeflexdashboard package,它是不是酒吧,但为您的目的可以罚款..

示例应用程序:

library(shiny) 
library(shinydashboard) 
library(flexdashboard) 


ui <- basicPage(flexdashboard::gaugeOutput("plt1")) 

server <- shinyServer(function(input, output, session) { 

    output$plt1 <- flexdashboard::renderGauge({ 
    gauge(15399, min = 0, max = 20000, symbol = '$', label = paste("Test Label"),gaugeSectors(
     success = c(15000,20000), warning = c(15000,1000), danger = c(0, 1000))) 

    }) 
}) 

shinyApp(ui = ui, server = server) 

(2)此功能可帮助您创建栏(github拍摄)

示例应用程序:

library(shiny) 
library(shinydashboard) 

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") 
) 
} 

ui <- dashboardPage(
    dashboardHeader(), 
    dashboardSidebar(disable = TRUE), 
    dashboardBody(uiOutput("plt1"))) 

server <- shinyServer(function(input, output, session) { 

output$plt1 <- renderUI({progressGroup(text = "A", value = 15399, min = 0, max = 20000, color = "green") 
    }) 
}) 

shinyApp(ui = ui, server = server) 
+0

Oleole

+0

我很抱歉上面的代码格式不正确,但是您是否知道如何在每次输入$ click_counter时动态改变表中的数字点击? – Oleole

+0

我建议使用'reactiveValues()'作为金钱 –