title: In R using Knitr, how can I get plotly charts created in a loop to print?
body: <p>I'm trying to create an HTML document using Knitr. I noticed you can get it to print regular plots created in a loop without any problem. However, plotly charts aren't as simple. For example, how can I get the following to work?</p>
  
  <pre><code>---
  title: "Test"
  output: html_document
  ---
  
  
  ```{r charts, echo=FALSE}
  
  library("plotly")
  
  charts&lt;-list()
  
  for(i in 1:length(unique(iris$Species))){
  
  iris2&lt;-iris[iris$Species==unique(iris$Species)[i],]
  
  charts[[i]]&lt;-plot_ly(iris2, x = ~Sepal.Length, y = ~Sepal.Width, type = 'bar')
  
  }
  
  print(charts)
  ```
  </code></pre>
  
  <p>The above does not work; the plots don't appear in the HTML document. However, the following does:</p>
  
  <pre><code>---
  title: "Test"
  output: html_document
  ---
  
  
  ```{r charts, echo=FALSE}
  
  library("plotly")
  
  charts&lt;-list()
  
  for(i in 1:length(unique(iris$Species))){
  
  iris2&lt;-iris[iris$Species==unique(iris$Species)[i],]
  
  charts[[i]]&lt;-plot_ly(iris2, x = ~Sepal.Length, y = ~Sepal.Width, type = 'bar')
  
  }
  
  charts[[1]]
  charts[[2]]
  charts[[3]]
  ```
  </code></pre>
  
  <p>I would just use to second option, but I don't know in advance how many charts will be created in the list which may be 50+, so it's not efficient to tell it to specifically print the first in the list, then the second, etc. like you see on the see above.</p>
  
  <p>Again, these plotly/interactive type of HTML plots don't appear work exactly the same way as regular plots, at least when printing them.</p>