简体   繁体   中英

How to make bar plot with dplyr in shiny dashboard

I am trying to make a bar plot in renderUI in shiny dashboard. Following is my code

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 is a function which returns a dataframe after cleaning and munging of a dataframe

Whenever I run shiny app it gives me Error:Mapping should be created with aes() or aes_() .` I do not know what exactly this means. When I run the same code in R console it gives me a proper 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") 

What I am doing wrong? please help

I got it where i was committing a mistake, in ui.R file instead of uiOutput I changed it to plotOutput and in the server.R file I changed it to renderPlot

Now everything works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM