2017-03-07 195 views
-1

我正在構建追蹤捐贈數量的閃亮應用程序。有沒有這種功能可以創建一個閃亮的反應棒?如果沒有,是否可以在HTML,CSS,JavaScript中做到這一點?閃亮:如何在閃亮的應用程序中添加響應欄

我想是這樣創造的東西:

enter image description here

+1

這是可能的,只要你有反應的數據集!示例代碼將是有用的! –

+0

@Malvina_a我已經有了一個被動數據集。我的問題是如何通過使用閃亮的功能,html,css等來創建類似上面的圖片。 – Oleole

+1

我已經理解了這個問題,但無論如何,創建具有示例數據的示例應用程序總是很好,所以有人希望幫助你,可以很容易地做到這一點... –

回答

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

錢< - 0 observeEvent(輸入$ click_counter,{ 錢< - 金錢+ 500 } 輸出$ PLT1 < - renderGauge({ 計(錢,分= 0, max = 20000,symbol ='$',label = paste(「donation」),gaugeSectors( success = c(15000,20000),warning = c(15000,1000),danger = c(0,1000)))) }) – Oleole

+0

我很抱歉上面的代碼格式不正確,但是您是否知道如何在每次輸入$ click_counter時動態改變表中的數字點擊? – Oleole

+0

我建議使用'reactiveValues()'作爲金錢 –