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.
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)
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())
})
}
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With