r - 如何从下拉列表中过滤数据?
问题描述
我想通过下拉列表过滤我的图表上的状态。例如,我有密度图和状态列表下拉列表,当我更改状态图时,应该将其更改为开启状态。但是,当我更改状态时,我的代码不会发生任何事情。
我的代码:
服务器
output$overat <- renderPlot({
filtered <-
Medi_sum_small %>%
filter(State == input$e1)
ggplot(Medi_sum_small, aes(Hospital_Ownership)) +
geom_density(aes(fill=factor(Hospital_overall_rating)), alpha=0.7) +
labs(x="Ownership",
fill="Overall rating") +
scale_x_discrete(labels = function(x) str_wrap(x,width=0.3))
})
用户界面
box(
title = "Select State"
,width = 3
,solidHeader = TRUE
,status = "primary"
,selectInput(
'e1', 'State',
c("All",unique(Medi_sum_small$State))
)
Graphs should be changed when I change the stage.
解决方案
现在我可以做到了,我将代码更改为:
output$overat <- renderPlot({
ggplot(filtered <-
Medi_sum_small %>%
filter(State == input$e1),
aes(Hospital_Ownership)) +
geom_density(aes(fill=factor(Hospital_overall_rating)), alpha=0.7) +
labs(x="Ownership",
fill="Overall rating") +
scale_x_discrete(labels = function(x) str_wrap(x,width=0.3))
})
太感谢了
推荐阅读
- javascript - 护照总是用 isAuthenticated() 返回 false
- python - Couchbase python模块:导入失败
- c - 如何从另一个文件中释放内存?
- sql - 对于每个 ID,获取 Product 不为空的第一条记录(Postgresql)
- swiftui - 将 AppDelegate 添加到项目以支持删除核心数据实体?
- python - 熊猫数据框中的条件fillna()
- java - HttpClient和HttpServer之间通信的Java问题
- django - 是否可以通过 settings.py 在 django 应用程序上自动运行功能?
- linux - 如何通过 ansible 创建指向 systemd 的链接
- django - Caddy 服务器:使用 docker-compose 在反向代理后面运行 Django 应用程序