[英]How to make bar plot with dplyr in shiny dashboard
我正在尝试在闪亮的仪表板的renderUI中绘制条形图。 以下是我的代码
output$city_plot <- renderUI({
clean_data(data) %>%
group_by(registrant_city) %>%
summarise(Total= n()) %>%
arrange(desc(Total)) %>%
ggplot(data=clean_data(data),aes(x= registrant_city, y = Total)) +
geom_bar(aes(fill= registrant_city), position = "dodge", stat = "identity")
})
clean_data
是一个在清理和整理数据帧之后返回数据帧的函数
每当我运行有光泽的应用程序时,都会出现Error:Mapping should be created with
aes()或aes_()
Error:Mapping should be created with
。`我不知道这到底意味着什么。 当我在R控制台中运行相同的代码时,它为我提供了适当的输入量。
data%>%
group_by(registrant_city) %>%
summarise(Total = n()) %>%
arrange(desc(Total)) %>%
top_n(n = 10) %>%
ggplot(aes(x= registrant_city, y = Total)) +
geom_bar(aes(fill=registrant_city), position = "dodge", stat = "identity")
我做错了什么? 请帮忙
我在ui.R
文件而不是uiOutput
中犯了一个错误,我将其更改为plotOutput
,在server.R
文件中将其更改为renderPlot
现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.