R闪亮的仪表图表

时间:2017-10-22 15:20:50

标签: r shiny gauge flexdashboard

有人可以帮我在R Shiny中绘制一个仪表图吗?我不需要它是动态的,但要有一个我赋值的KPI并显示当我运行app时它应该是红色的从0到0.3,黄色从0.3到0.5,绿色从0.5到1。

2 个答案:

答案 0 :(得分:10)

flexdashboard提供了这样的仪表图表:

library(shiny)
library(flexdashboard)

ui <- fluidPage(
  numericInput("value", label = "Select value", min = 0, max = 1, value = 0.5, step = 0.1),
  gaugeOutput("gauge")
)

server <- function(input, output) {

  output$gauge = renderGauge({
    gauge(input$value, 
          min = 0, 
          max = 1, 
          sectors = gaugeSectors(success = c(0.5, 1), 
                                 warning = c(0.3, 0.5),
                                 danger = c(0, 0.3)))
  })
}

shinyApp(ui = ui, server = server)

enter image description here

答案 1 :(得分:3)

您还可以使用C3

#devtools::install_github("FrissAnalytics/shinyJsTutorials/widgets/C3")
library(C3)
library(shiny)

runApp(list(
  ui = bootstrapPage(
    # example use of the automatically generated output function
    column(6,C3GaugeOutput("gauge1"))
  ),
  server = function(input, output) {

    # reactive that generates a random value for the gauge
    value = reactive({
      invalidateLater(1000)
      round(runif(1,0,100),2)
    })

    # example use of the automatically generated render function
    output$gauge1 <- renderC3Gauge({ 
      # C3Gauge widget
      C3Gauge(value())
    })
  }
))

enter image description here