title: Creating a Shiny app with real time data
body: <p>I am trying to create a Shiny app to display data that is collected real time. For this I am using <code>invalidateLater(5000, session)</code> to periodically update the data in R.</p>
  
  <p>Here is the outline of my <code>server.R</code> file:</p>
  
  <pre><code>library(shiny)
  library(magrittr)
  
  # Function to get new observations
  get_new_data &lt;- function(){
      data &lt;- rnorm(5) %&gt;% rbind %&gt;% data.frame
      return(data)
  }
  
  # Initialize my_data
  my_data &lt;- get_new_data()
  
  # Function to update my_data
  update_data &lt;- function(){
      my_data &lt;- rbind(get_new_data(), my_data)
  }
  
  shinyServer(function(input, output, session){
  
    # Plot the 30 most recent values
    output$first_column &lt;- renderPlot({
      invalidateLater(5000, session)
      update_data()
      plot(X1 ~ 1, data=my_data[1:30,], ylim=c(-3, 3), las=1)
    })
  
  })
  </code></pre>
  
  <p>The problem I am having is that I want to show the <em>N</em> most recent values but can't figure out how to keep the old values. So instead of plotting the most recent 30 values I get a plot of 1 value.</p>
  
  <p>Does anyone know the correct way to setup a Shiny app to update with new data while keeping the old?</p>