Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R shiny gauge chart

Could someone help me draw a gauge chart in R Shiny?I don`t need it to be dynamic, but to have a KPI that I assign with a value and to show that when I run the app.It should be red from 0 to 0.3, yellow from 0.3 to 0.5 and green from 0.5 to 1.

like image 539
Andreea Avatar asked Oct 22 '17 15:10

Andreea


2 Answers

flexdashboard provides such a gauge chart:

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

like image 176
shosaco Avatar answered Nov 09 '22 07:11

shosaco


You can also use C3 library

#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

like image 7
Pork Chop Avatar answered Nov 09 '22 05:11

Pork Chop