title: avoid double refresh of plot in shiny
body: <p>In a shiny plot I am trying to highlight points matching a clicked point (based on nearPoints() and click).</p>
  
  <p>It sort of works.  However, the reactive parts of the shiny app are refreshed twice and the second iteration seems to clear the clicked information.</p>
  
  <p>How can I avoid the second refresh of the app?</p>
  
  <p>Here is the MWE:</p>
  
  <pre><code>library("Cairo")
  library("ggplot2")
  library("shiny")
  
  ui &lt;- fluidPage(
    fluidRow(
      titlePanel('Phenotype Plots')
    ),
  
    fluidRow(
      uiOutput("plotui")
    ),
  
    hr(),
  
    fluidRow(
  
      wellPanel(
        h4("Selected"),
        tableOutput("info_clicked")
        ##dataTableOutput("info_clicked") ## overkill here
      )
    )
  )
  
  
  server &lt;- function(input, output, session) {
  
    selected_line &lt;-  reactive({
      nearPoints(mtcars, input$plot_click,
                 maxpoints = 1,
                 addDist = TRUE)
    })
  
    output$plotui &lt;- renderUI({
        plotOutput("plot", height=600,
          click = "plot_click"
        )
      })
  
    output$plot &lt;- renderPlot({
  
      p &lt;- ggplot(mtcars) +
        facet_grid(am ~ cyl) +
        theme_bw() +
        geom_point(aes(x=wt, y=mpg))
  
      sline &lt;- selected_line()
      if (nrow(sline) &gt; 0) {
        p &lt;- p +
          geom_point(aes(x=wt, y=mpg),
                     data=mtcars[mtcars$gear == sline$gear,],
                     colour="darkred",
                     size=1)
      }
  
      p
  
    })
  
    ##output$info_clicked &lt;- renderDataTable({
    output$info_clicked &lt;- renderTable({
      res &lt;- selected_line()
      ## datatable(res)
      res
    })
  
  }
  
  shinyApp(ui, server)
  </code></pre>