title: Conditional reactivity Shiny
body: <p>Reactive expressions in Shiny propagate changes where they need to go. We can suppress some of this behaviour with <code>isolate</code>, but can we suppress changes being propagated based on our own logical expression?</p>
  
  <p>The example I give is a simple scatterplot, and we draw a crosshair with <code>abline</code> where the user clicks. Unfortunately, Shiny considers the result to be a new plot, and our click value is reset to <code>NULL</code>... which in turn is treated as an update to the value to be propagated as usual. The plot is redrawn, and <code>NULL</code> is passed to both arguments of <code>abline</code>.</p>
  
  <p>My hack (commented out below) is to place a condition in the <code>renderPlot</code> call which updates some non-reactive variables for the plotting coordinates, only when the click values are non-<code>NULL</code>. This works fine for trivial plots, but it actually results in the plot being drawn twice.</p>
  
  <p>What's a better way to do this? Is there a <em>correct</em> way?</p>
  
  <p>Server file:</p>
  
  <pre><code>library(shiny)
  
  shinyServer(function (input, output)
  {
    xclick &lt;- yclick &lt;- NULL
    output$plot &lt;- renderPlot({
      #if (!is.null(input$click$x)){
        xclick &lt;&lt;- input$click$x
        yclick &lt;&lt;- input$click$y
      #}
      plot(1, 1)
      abline(v = xclick, h = yclick)
    })
  })
  </code></pre>
  
  <p>UI file:</p>
  
  <pre><code>library(shiny)
  
  shinyUI(
    basicPage(
      plotOutput("plot", click = "click", height = "400px", width = "400px")
    )
  )
  </code></pre>