DS4PS / cpp-526-spr-2021

Course shell for Foundations of Data Science I
https://ds4ps.org/cpp-526-spr-2021/
MIT License
1 stars 2 forks source link

Lab 4: Reactive Object - not seeing inputId #9

Open sjone128 opened 3 years ago

sjone128 commented 3 years ago

When adding the reactive object to my code I'm getting this error:

Reactive Object

one.team <- filter(.data = Teams, names == input$my.team)

Error Message

Quitting from lines 73-451 (lab-04-template.rmd) Warning: Error in : Problem with filter() input ..1. x Can't access reactive value 'my.team' outside of reactive consumer. i Do you need to wrap inside reactive() or observer()? i Input ..1 is names == input$my.team. 152: 'rlang:: last_error()' to see where the error occurred.

Look a little further

rlang::last_error() <error/dplyr_error> Problem with filter() input ..1. x object 'input' not found i Input ..1 is name == input$my.team.

Backtrace:

  1. dplyr::filter(.data = Teams, name == input$my.team)
  2. base::.handleSimpleError(...)
  3. dplyr:::h(simpleError(msg, call))

My guess is that my. team object wasn't created properly but I am not seeing my error. See below:

selectInput( inputId= 'my.team', label='Select a Team', choices= c("Oakland Athletics", "San Diego Padres", "Seattle Mariners", "San Francisco Giants", "New York Mets", "Arizona Diamondbacks", "New York Yankees", "St. Louis Cardinals", "Miami Marlins", "Pittsburgh Pirates", "Philadelphia Phillies", "St. Louis Cardinals", "Chicago White Sox", "Detroit Tigers", "Boston Red Sox", "Baltimore Orioles"), selected= "Arizona Diamondbacks"
)

Thanks for the help!

jamisoncrawford commented 3 years ago

@sjone128 you've put together the selectInput() function perfectly fine, as long as it's in your UI section or ui.R file.

Typically, what your error message means, is that you called a reactive value like input$my.team outside of a reactive scope, which are demarcated with the curly braces, e.g. ({ ... }). Try performing your filter() operation in your render*({}) function instead.

Let us know if this works!

S-Jones-ASU commented 3 years ago

@jamisoncrawford, thanks for the tip.

I moved the reactive element to the render*({}) function with no success, yet.

jamisoncrawford commented 3 years ago

Would you please email me your .R file(s) and I can take a better look?

jamisoncrawford commented 3 years ago

Actually we have a meeting tonight, yeah? @S-Jones-ASU

sjone128 commented 3 years ago

@jamisoncrawford yep! We do at 3 pm PST.