title: Shiny Plotly reactive data plot
body: <p>I've put together this Shiny app from tutorial and examples, and I've become stuck. My aim is to make the plot reactive, so that the data points in 'uval$df' are plotted, meaning that selected points will be removed from the graph, and it can't be selected twice. How do I do this? (I've got a feeling it's something lacking in my basic understanding)</p>
  
  <p>Thanks!</p>
  
  <pre><code>library(shiny)
  library(plotly)
  library(dplyr)
  
  ui &lt;- fluidPage(
    fluidRow(
      column(12,plotlyOutput("plot"),
             verbatimTextOutput("txtout1"),
             verbatimTextOutput("txtout2"),
             verbatimTextOutput("txtout3"))
    )
  )
  
  server &lt;- function(input, output, session) {
  x&lt;-c(1,2,34,2,1,23,24)   
  y&lt;-c(10,20,30,40,50,60,70)
  df&lt;-data.frame(x,y)
  vector.is.empty &lt;- function(x) return(length(x) ==0 )
  
  K &lt;-reactive({
    event_data("plotly_selected",source = "B")
  })
  
  M&lt;-reactive({
    K()[,c("x","y")]
  })
  
  values &lt;- reactiveValues()
  values$df &lt;- data.frame(x = numeric(0), y = numeric(0))
  newEntry &lt;- observeEvent(K(),priority = 1,{
      new0 &lt;- isolate(M())
      isolate(values$df &lt;- rbind(values$df, new0))
  })
  
  uval &lt;- reactiveValues()
  uval$df &lt;- df
  newEntry1 &lt;- observeEvent({values$df},priority = 2,{
    new1 &lt;- isolate(data.frame(values$df))
    isolate(uval$df &lt;- setdiff(df,new1))
  })
  
  output$plot &lt;- renderPlotly({
    plot_ly(x = df$x, y = df$y, mode = "markers",source="B") %&gt;%
      layout(dragmode =  "select", title = "Original Plot", font=list(size=10))
  })
  
  output$txtout1 &lt;- renderPrint({
    if(vector.is.empty(K())) "Click and drag across points" else M()
  })
  
  output$txtout2 &lt;- renderPrint({
    uval$df
  })
  
  output$txtout3 &lt;- renderPrint({
    values$df
  })
  
  }
  
  shinyApp(ui, server, options = list(display.mode = "showcase"))
  </code></pre>