title: Making code run on click R presentation
body: <p>I'm currently making a presentation using Rstudio's R presentation functionality.</p>
  
  <p>I have an algorithm which loops through and plots a graph every second or two.
  The algorithm can be called via <code>RunAlgorithm()</code></p>
  
  <pre><code>RunAlgorithm&lt;-function(){
      for(i in 1:10){
          x&lt;-rnorm(1000)
          y&lt;-runif(1000)
          plot(x,y)
          Sys.sleep(1)
      }
  }
  </code></pre>
  
  <p>I want to show this algorithm running in the presentation. But when I use it in the file (below), I just get a whole page of each individual plot, one displayed right after the next</p>
  
  <p><a href="https://i.stack.imgur.com/FL3bM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FL3bM.png" alt="enter image description here"></a></p>
  
  <h1>TestFile.Rpres</h1>
  
  <pre><code>    TestFile
  ========================================================
  author: me
  date: today
  
  First Slide
  ========================================================
  ```{r echo = FALSE}
  RunAlgorithm&lt;-function(){
          for(i in 1:10){
              x&lt;-rnorm(1000)
              y&lt;-runif(1000)
              plot(x,y)
              Sys.sleep(1)
          }
  }
  RunAlgorithm()
  
  ```
  Slide With Code
  ========================================================
  
  
  Slide 2
  </code></pre>
  
  <p>What I would like is some way to click a button, or turn onto this slide and have the animation play in browser</p>