R闪亮仪表图
R shiny gauge chart
有人可以帮我在 R Shiny 中画一个仪表图吗?我不需要它是动态的,但要有一个我分配了值的 KPI 并显示当我 运行 app.It 0 到 0.3 应该是红色,0.3 到 0.5 应该是黄色,0.5 到 1 应该是绿色。
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)
您还可以使用 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())
})
}
))
有人可以帮我在 R Shiny 中画一个仪表图吗?我不需要它是动态的,但要有一个我分配了值的 KPI 并显示当我 运行 app.It 0 到 0.3 应该是红色,0.3 到 0.5 应该是黄色,0.5 到 1 应该是绿色。
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)
您还可以使用 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())
})
}
))