如何在闪亮的仪表板中使用 dplyr 制作条形图

How to make bar plot with dplyr in shiny dashboard

我正在尝试在 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 是一个函数,它 returns 清理和修改数据帧后的数据帧

每当我 运行 闪亮的应用程序时,它都会给我 Error:Mapping should be created withaes() 或 aes_()。`我不知道这到底是什么意思。当我 运行 在 R 控制台中使用相同的代码时,它会给我一个正确的 ootput。

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

现在一切正常。