title: Plotly plot doesn't render within for loop of RMarkdown document
body: <p>I'm trying to build a report dynamically that requires running a loop, and for each iteration printing some messages, tables, and a plot. I can get everything to work <em>except</em> for the plot.</p>
  
  <p><em>example.rmd</em></p>
  
  <pre><code>```{r echo=FALSE, results='asis', fig.keep='all', message = FALSE, warning = FALSE}
  library(knitr)
  library(plotly)
  
  for(i in 1:4){
    foo &lt;- iris[sample(nrow(iris), 20), ]
  
    cat("\n")
    cat("# Iteration", i, "\n")
  
    # Print the first few lines
    print(kable(head(foo)))
    cat("\n")
  
    # Plot Sepal.Width vs Petal.Length using ggplotly()
    plt &lt;- ggplot(foo, aes(x = Sepal.Width, y = Petal.Length))+geom_point()
  
    # plot(plt)  # &lt;- this works
    # plot(ggplotly(plt))  # &lt;- this doesn't work
    # ggplotly(plt)  # &lt;- this doesn't work
  
    cat("\n")
  }
  ```
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eAJJt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eAJJt.png" alt="enter image description here"></a></p>
  
  <p>How can I get the plotly plots to render in my report?</p>