title: Add elements to plot dynamically in shiny
body: <p>I have constructed a shiny app which allows users to enter bivariate data, and, through a sequence of clicks, produce a scatterplot, then add the correlation coefficient as to the plot as text, and lastly add the regression line with its equation.  </p>
  
  <p>I am trying to emulate that procedure in an app which first generates a 'random' scatterplot with a click.  Somehow the random generation of the bivariate data is screwing the process of plotting up because the x and y values seem somehow not to persist to generate subsequent plots.  The values are there somewhere because the correlation and regression equation are produced on the second and third clicks as required.  The app uses some source code to call functions to produce random bivariate data, make plots, and produce the regression coefficients.  I have not included it below because I have run it all separately and it works fine.  Anyway, here's my code:</p>
  
  <h1>ui.R</h1>
  
  <pre><code>    library(shiny)
      source('binorm.R')
  
      ui&lt;-fluidPage(
      withMathJax(),
      tags$style(type = "text/css",
           "h1 {color: blue; font-weight: bold; font-size: 24px;}",
           "h4 {color: blue; font-weight: bold; font-size: 18px;}",
           "body {background-color: gold;}",
           "label {font-size: 16px; color: blue;
                 font-weight: bold;}"
            ),
      tags$head(tags$style(HTML(
          "#r {font-size: 15px; color: red; font-weight: bold;}"))),
      tags$head(tags$style(HTML(
          "#reg {font-size: 15px;color: red; font-weight: bold;}"))),
      tags$h1('Guess the Correlation Coefficient, r'),
      fluidRow(
  
      column(9,
      plotOutput('plot', height="600px", width='100%')),
  
      column(3,
      hr(),
      h4("Generate a 'Random' Scatterplot"),
      actionButton(inputId='go1', label='Get New Scatterplot',
       style="color: blue; font-size: 16px; font-weight: bold; 
                 background-color: white;"),
  
     hr(),
  
  
     h4('Reveal Correlation'),
     actionButton(inputId='go2', label='Show r',
       style="color: blue; font-size: 16px; font-weight: bold; 
                 background-color: white;"),
  
     hr(),
  
     verbatimTextOutput('r'),
  
     h4('Show the Regression Line, y on x'),
     actionButton(inputId='go3', label='Show Regression Equation',
       style="color: blue; font-size: 16px; font-weight: bold; 
                 background-color: white;"),
     hr(),
     verbatimTextOutput('reg')
           )
        )
      )
  </code></pre>
  
  <h1>server.R</h1>
  
  <pre><code>server&lt;-function(input, output){
  
          v&lt;-reactiveValues(M=rbivariate(rpar(200)), r=FALSE, reg=FALSE)
          observeEvent(input$go1, {v$r&lt;-FALSE})
          observeEvent(input$go1, {v$reg&lt;-FALSE})
          observeEvent(input$go1, {v$M&lt;-rbivariate(rpar(200))})
          observeEvent(input$go2, {v$r&lt;-TRUE})
          observeEvent(input$go3, {v$reg&lt;-TRUE})
          output$plot&lt;-renderUI({
                     if (v$r==FALSE){
                           S1plot(v$M[,1], v$M[,2])}
                     else if (v$r==TRUE &amp; v$reg==FALSE){
                           Rplot(v$M[,1], v$M[,2])}
                     else if (v$r==TRUE &amp; v$reg==TRUE){
                           L1plot(v$M[,1], v$M[,2])}
                                  })         
          output$r&lt;-renderPrint({
                     if(v$r==TRUE){print(cex=2,paste0(
                              'r= ',
                               rcfs(v$M[,1], v$M[,2])[3]))}
                     else {print('What is r?')}
                               })
           output$reg&lt;-renderPrint({
                     if(v$reg==TRUE){print(cex=2,paste0(
                              'y=(',
                               rcfs(v$M[,1],v$M[,2])[1],')x+(',
                               rcfs(v$M[,1],v$M[,2])[2],')'))
                               }
                     else {print('Regression Equation?')}
                               })                                                            
                              }
  </code></pre>