【问题标题】:shiny: how to add a reactive bar in shiny app闪亮的:如何在闪亮的应用程序中添加反应栏
【发布时间】:2017-07-27 14:33:35
【问题描述】:

我正在构建一个众筹闪亮的应用程序,用于跟踪捐赠了多少。是否有这样的功能可以在闪亮的状态下创建反应条?如果没有,是否可以在 html,css,javascript 中执行此操作?

我想创建这样的东西:

【问题讨论】:

  • 只要你有响应式数据集就可以!示例代码会很有用!
  • @Malvina_a 我已经有一个反应数据集。我的问题是如何使用闪亮的函数、html、css 等创建类似上图的内容。
  • 我已经理解了这个问题,但无论如何,使用示例数据创建示例应用程序总是好的,因此想要帮助您的人可以轻松完成......

标签: javascript html shiny shinyjs


【解决方案1】:

我有两个解决方案给你:

(1) 我可以推荐你使用flexdashboard package 中的gauge,它不是酒吧,但对于你的目的来说可以。..

示例应用:

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)

【讨论】:

  • money
  • 我很抱歉我上面的代码格式不正确,但是你知道如何让仪表中的数字在每次点击 input$click_counter 时动态变化吗?
  • 我建议使用reactiveValues() 来赚钱
猜你喜欢
  • 2020-06-16
  • 2018-12-29
  • 2013-07-16
  • 2014-06-07
  • 2013-07-08
  • 1970-01-01
  • 2016-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多