r - How can I use a reactive filtered dataset within a gauge plot?
问题描述
I'm relatively new to shiny
and flexdashboard
, but I'm trying to produce a gauge chart from a filtered dataset.
The goal is to filter a dataset on a variable (in the ReprEx it is gear
), and then extract the lowest value in another variable from the filtered dataset (in the ReprEx, I want to find the lowest mpg
).
First off, I select the input.
selectInput("x", "Gear", choices = mtcars$gear)
Then I'm currently creating a reactive dataset with a filter for gear in the sidebar.
df <- reactive({
mtcars %>% filter(gear == input$x)
})
Finally I'm rendering the gauge plot, trying to extract the column mpg
into a vector x
, and then inputting the min(x)
into the gauge chart.
renderPlot({
x <- df()[,"mpg"]
gauge(min(x), min = 0, max = 50, gaugeSectors(
success = c(41, 50), warning = c(21, 40), danger = c(0, 20)
))
})
Where in this process am I going wrong?
Thanks.
解决方案
你应该使用renderGauge
而不是renderPlot
推荐阅读
- javascript - 为什么我会收到这些未定义的值?
- django - 将 .git 文件夹添加到 Github 是一种好习惯吗?
- ffmpeg - 将 AVI 转码为 DNxHD mov – 仅输出视频的前几秒
- javascript - 覆盖javascript中的全局变量
- callback - 是否可以使用回调来访问 Julia 的微分方程集合问题中的单个轨迹?
- javascript - Apiv2Error:无法在该用户名下签署清单
- rust - 如何遍历(巨大的)gzip 压缩文件的行?
- python - Python:标准化矩阵
- java - 来自 Java 程序的动态屏蔽
- artifactory - 全新安装 Artifactory OSS 7.12.6 无法启动,缺少 jffe 服务