Shiny App Error: Aesthetics must be either length 1 or the same as the data (1): x

Viewed 53

I'm teaching myself r and i'm trying to create a shiny app on NBA data and i'm asking for the name of player and the statistic for the inputs.

 textInput("name", "Name", value = "Giannis Antetokounmpo"),
      
 selectInput("stat", "Stat", choices = list("Points Per Game" = "PTS",
                                                 "Rebounds Per Game" = "TRB",
                                                 "Assits Per Game" = "AST",
                                                 "Steals Per Game" = "STL",
                                                 "Blocks Per Game" = "BLK"),
                                                  selected = "PTS"),

When trying to create a scatterplot i am getting the error that "Aesthetics must be either length 1 or the same as the data"

    NBA_abv %>% 
      filter(Player == input$name) %>%
      ggplot(aes(x = Year, y = input$stat)) + geom_point() + geom_line()

Here is the dataset i'm using

1 Answers

I think I have come across this error once before. If I remember correctly, you need to use aes_string

    NBA_abv %>% 
      filter(Player == input$name) %>%
      ggplot(aes_string(x = Year, y = input$stat)) + geom_point() + geom_line()
Related