title: Change plot on click in Shiny
body: <p>I hope you can help me again as I stumbled over another problem in Shiny:</p>
  
  <p>I would like a graphic to change in the moment it is clicked on. Here's a minimal example:</p>
  
  <p>ui.R (shows a clickable graphic and a text frame)</p>
  
  <pre><code>shinyUI(fluidPage(
    titlePanel("Title"),
    sidebarLayout(
      sidebarPanel(
      ),
      mainPanel(
        plotOutput("graph", width = "100%", click = "plot_click"),
        verbatimTextOutput("click_info")
      )
    )
  ) 
  ) 
  </code></pre>
  
  <p>server.R (graphic just contains "A","B","C","D", on click I get the nearest letter in the text frame)</p>
  
  <pre><code>shinyServer(function(input, output, session) {
  
    # Visualization output:  
    observe({
      output$graph &lt;- renderPlot({
        data &lt;- data.frame(x=c(1,2,1,2), y=c(1,1,2,2), 
                values=c("A","B","C","D"), stringsAsFactors=FALSE)
        plot(data$x, data$y, pch=data$values)
      })  
    })
  
    # interaction click in graph  
    observe({
      click &lt;- c(input$plot_click$x, input$plot_click$y)
      data &lt;- data.frame(x=c(1,2,1,2), y=c(1,1,2,2),
                         values=c("A","B","C","D"), stringsAsFactors=FALSE)
      nearest_point &lt;- which.min(apply(data[,1:2], 1, function(a) sum(((click-a)^2))))
      id &lt;- data$values[nearest_point]
      output$click_info &lt;- renderPrint({
        id
      })
    })
  })
  </code></pre>
  
  <p>Now what I want is to mark the letter I clicked on in the graph, for example by another color. But all my tries failed so far.</p>