title: Shiny Plotly R - Maintain zoom after rerender
body: <p>Is there any way to maintain my view (zoom level/ extents), in shiny plotly in R, as a plot re-renders? </p>
  
  <p>I've a plot from which selected values are removed, after which the plot re-renders (as no delete traces in R?). I then have to navigate back to the area of interest on the plot. This slows the process a great deal, is there any way around this?</p>
  
  <p>Thanks.</p>
  
  <pre><code>library(shiny)
  library(plotly)
  library(dplyr)
  
  ui &lt;- fluidPage(
    fluidRow(
      column(12,plotlyOutput("plot"),
             actionButton("addButton", "Save Edits"),
             verbatimTextOutput("txtout1"),
             verbatimTextOutput("txtout2"),
             verbatimTextOutput("txtout3"))
    )
  )
  
  server &lt;- function(input, output, session) {
  x&lt;-c(1,2,3,4,5,6,7)   
  y&lt;-c(10,10,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(),{
    if(!vector.is.empty(K())){
      new0 &lt;- isolate(M())
      isolate(values$df &lt;- rbind(values$df, new0))
   }
  })
  
  uval &lt;- reactiveValues()
  uval$df &lt;- df
  newEntry1 &lt;- observeEvent({values$df},{
    if(!vector.is.empty(K())){
    new1 &lt;- isolate(data.frame(values$df))
    fnew1 &lt;- filter(df, !(df$x %in% new1$x))
    isolate(uval$df &lt;-  fnew1)
    }
  })
  
  output$plot &lt;- renderPlotly({
    plot_ly(uval$df, x = x, y = y, mode = "markers",source="B") %&gt;%
      layout(title = "Original Plot", font=list(size=10))
  })
  
  addData &lt;- observe({
    if(input$addButton &gt; 0) {
       save_data &lt;&lt;- isolate(uval$df)
    }
  })
  
  output$txtout1 &lt;- renderPrint({
    if(vector.is.empty(K())) "Click and drag across points" else M()
   #nrow(df)
  })
  
  output$txtout2 &lt;- renderPrint({
    #nrow(uval$df)
    uval$df
  })
  
  output$txtout3 &lt;- renderPrint({
    #nrow(values$df)
    values$df
  })
  
  }
  
  shinyApp(ui, server, options = list(display.mode = "showcase"))
  </code></pre>