mortonanalytics / myIO

Open Source Project to illustrate R+ d3.js DOM manipulation and plotting
MIT License
5 stars 1 forks source link

Create draggable scatterplot with regression line #11

Open mortonanalytics opened 6 years ago

mortonanalytics commented 6 years ago

Per: https://stackoverflow.com/questions/47280032/draggable-line-chart-in-rshiny

mortonanalytics commented 6 years ago

Added draggable lines; able to return new data points.

TODO: calculate linear estimates; return data to Shiny (if needed)

mortonanalytics commented 6 years ago

Completed with f6788699d9f53e1c9c602284c5bab8c22ce20d93.

Sends points and regression output to Shiny as server inputs: myIOpoints and myIOregression.

Sorry this took so long. I'll put a demo up tomorrow.

mortonanalytics commented 6 years ago

Resize is not right, but it corrects after dragging a point. I'll have to debug this later though or just trigger a full redraw. In the meantime, the demo app has an example: http://www.morton-analytics.com/shiny/myio_demo/ (under the line chart > regression line tabs).

Usage in app looks like this with magittr piping:

output$regLine <- renderMyIO({
    myIO() %>%
      addIoLayer(type = 'point',
                 color = 'steelblue',
                 label = 'MPG',
                 data = mtcars[order(mtcars$mpg),],
                 mapping = list(x_var = "wt",
                                y_var = "mpg")) %>%
      myIO::dragPoints()
  })

    output$dragPoints <- renderTable({
      req(input$myIOpointsX)
      data.frame(x = input$myIOpointsX,
                 y = input$myIOpointsY,
                 estimate = input$myIOpointsEst)
      })