Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data/reactives code updated #2

Open
cmainov opened this issue Jul 15, 2022 · 3 comments
Open

Data/reactives code updated #2

cmainov opened this issue Jul 15, 2022 · 3 comments

Comments

@cmainov
Copy link
Collaborator

cmainov commented Jul 15, 2022

Hey Jesse,

It turns out the solution to my problem was indeed harnessing a dataset in long format. This made reactive filtering quite easy to implement and I was able to streamline and minimize redundant code. I know you said you wanted to look at the code when it was updated and working. The relevant changes are in the "app.r" file and the data steps are in "09-Shapefiles-for-Shiny-App.R". The elements of the dashboard are currently functioning as intended in this version. My next step will be to incorporate the MSA plots, most likely in a separate tab.

Thanks

Chris

@lecy
Copy link
Member

lecy commented Jul 15, 2022

A couple of things:

I think you can define the reactive function outside of server. Think about it as your data filter step:

data_reactive <- reactive({
    
      if (input$ptype=="dorling") 
      { filter( cnties.dorling, year ==  input$yr_select ) }
      if (input$ptype=="chloro") {
      { filter( cnties, year == input$yr_select ) }

} )

Makes the server code a lot cleaner:

  # select plotting data 
  df.plot <- data_reactive()

  # plot type
  output$ptype <- renderPlot({ lp.plot.chloro( df = df.plot ) })

@cmainov
Copy link
Collaborator Author

cmainov commented Jul 15, 2022

sounds good. I will update accordingly!

@lecy
Copy link
Member

lecy commented Jul 15, 2022

There's an extra { in the reactive function above, FYI. Just saw it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants