1

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

markus
  • 25,843
  • 5
  • 39
  • 58
zambini
  • 19
  • 1
  • 2
    Related: [Why do I have to use aes_string() with ggplot in shiny?](https://stackoverflow.com/questions/63734097/why-do-i-have-to-use-aes-string-with-ggplot-in-shiny) – markus Aug 07 '22 at 10:12
  • 1
    Does this answer your question? [Why do I have to use aes\_string() with ggplot in shiny?](https://stackoverflow.com/questions/63734097/why-do-i-have-to-use-aes-string-with-ggplot-in-shiny) – mhovd Aug 07 '22 at 14:17

1 Answers1

0

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()
amanwebb
  • 380
  • 2
  • 9