0

I'm new to Shiny/shinydahsboard and am working on a project to get better at it. I keep running into an issue with plotly and goem_bar or geom_col plots. I get the error that the aesthetic is missing even though it's included in ggplot().

I was also trying to work in flexdashboard and ran into a similar issue where I would get the error geom_col() requires the following missing aesthetics: x and y, but I could get it to work with a regular non-plotly plot in both cases.

Any insight would be appreciated! Thank you!

Data

I'm using df %>% count(Loc) which equates to this outcome for testing purposes:

df2 <- data.frame (Loc = c("Los Angeles", "New York City", 
"Seattle"),  n = c(337, 233, 304))

df2 <- as.tibble(df2)

Code

header <- dashboardHeader(title="Employee Dashboard")

sidebar <- dashboardSidebar()

body <- dashboardBody(
          fluidRow(
            box(
              plotlyOutput("loc_plot"))
      )
)


ui <- dashboardPage(header, sidebar, body)


server <- function(input, output, session) {


    output$loc_plot <- renderPlotly({
        loc_plotly <- df2 %>%    
          ggplot(aes(x=Loc, y=n)) +
          geom_col(fill= "#2171B5")
    
        ggplotly(loc_plotly)
    })
  
}

shinyApp(ui=ui, server=server)`

Error enter image description here`

stefan
  • 90,330
  • 6
  • 25
  • 51

0 Answers0