Skip to content

Reactivity/solution_05b uses rbind more than necessary #5

Description

@grntlngdn

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions