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

Reactivity/solution_05b uses rbind more than necessary #5

Open
grntlngdn opened this issue Feb 13, 2019 · 0 comments
Open

Reactivity/solution_05b uses rbind more than necessary #5

grntlngdn opened this issue Feb 13, 2019 · 0 comments

Comments

@grntlngdn
Copy link

Is there a reason that the following doesn't demonstrate a more efficient solution?

  rv <- reactiveValues(points = cars)
  
  # Same as Solution_05a.R, but instead of keeping
  # track of the single most recent point, we accumulate
  # all previous points using rbind().
  observeEvent(input$click, {
    if (!is.null(input$click)) {
      thisPoint <- data.frame(
        speed = input$click$x,
        dist = input$click$y
      )
      rv$points <- rbind(rv$points, thisPoint)
    }
  })
  
  output$plot <- renderPlot({
    df <- rv$points
    plot(df, pch = 19)
    
    model <- lm(dist ~ speed, df)
    abline(model)
  })
}

As Joe Cheng does, I'd like to recognize that while rbind works fairly quickly usually, it seems like this demonstrates how things could be done slightly more efficiently in general

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

1 participant