title: Remembering Selected Points on Plot in Shiny
body: <p>I'm trying to create an interactive k-means plot that will allow people to see the effects of their inputs (like specifying centers as opposed to purely random selection) but running in to an issue with my Shiny code. I'm trying to understand how I can select a point and have my app remember it to use as a center. I've been searching for a way to do this with reactive code but everything I've tried so far has failed. My current working code is as below:</p>
  
  <pre><code># Pre Work
  library(ggfortify)
  dsnames &lt;- names(iris[1:4])
  cb_options &lt;- list()
  cb_options[dsnames] &lt;- dsnames
  
  # UI
  shinyUI &lt;- fluidPage(
    titlePanel("Interactive K-Means Clustering Using Iris Dataset"),
    sidebarPanel(
      numericInput("numCenter", label=h4("Centers for k-means:"), min=2, max=30, value=3),
      selectInput("xaxisGrp","X-Axis:", c("1"="1","2"="2"), choices=cb_options),
      selectInput("yaxisGrp","Y-Axis:", c("1"="1","2"="2"), choices=cb_options),
      tableOutput("info")
    ),
    mainPanel(
      plotOutput("plot1", click="plot_click", dblclick="plot_dbl")
    )
  )
  
  # Server
  shinyServer &lt;- function(input, output, session) {
  
    iris_k &lt;- reactive({
      kmeans(iris[1:4], centers=input$numCenter)
    })
  
    output$plot1 &lt;- renderPlot({
      ggplot() + geom_point(data=iris, aes_string(input$xaxisGrp, input$yaxisGrp), colour=iris_k()$cluster)
    })
  
    output$info &lt;- renderTable({
      nearPoints(iris, input$plot_click, xvar=input$xaxisGrp, yvar=input$yaxisGrp)[,c(input$xaxisGrp, input$yaxisGrp)]
    })
  
  }
  
  # ShinyApp function call
  shinyApp(ui=shinyUI, server=shinyServer)
  </code></pre>
  
  <p>How can I achieve this?</p>