title: Using `ggplotly` and `DT` from a `for` loop in Rmarkdown
body: <p>Is that possible to use <code>ggplotly()</code> or <code>datatable()</code> in RMarkdown from inside a <code>for</code> loop or function? Example:</p>
  <pre><code>---
  title: &quot;Using `ggplotly` and `DT` from a `for` loop in Rmarkdown&quot;
  output: html_document
  ---
  
  ```{r setup, include=FALSE}
  library(ggplot2); library(DT)
  ```
  
  ## Without `for` loop - works
  
  ```{r}
  datatable(cars)
  
  g &lt;- ggplot(cars) + geom_histogram(aes_string(x=names(cars)[1] ))
  ggplotly(g) 
  ```
  
  ## From inside the `for` loop  - does not work (nothing is printed)
  
  ```{r}
  for( col in 1:ncol(cars)) {
  
    datatable(cars)          # &lt;-- does not work 
    print( datatable(cars) ) # &lt;-- does not work either
  
    g &lt;- ggplot(cars) + geom_histogram(aes_string(x=names(cars)[col] ) )
  
    ggplotly (g)            # &lt;-- does not work 
    print ( ggplotly (g) )  # &lt;-- does not work either
  }
  ```
  </code></pre>
  <p>I wonder if this is because <em>interactive</em> outputs cannot be <code>print</code>-ed at all - by design.<br />
  No such problem existing when printing non-interactive outputs.</p>
  <p>PS
  This is related to:
  <a href="https://stackoverflow.com/questions/48868942/automating-the-generation-of-preformated-text-in-rmarkdown-using-r">Automating the generation of preformated text in Rmarkdown using R</a><br />
  <a href="https://stackoverflow.com/questions/56468804/looping-headers-sections-in-rmarkdown">Looping headers/sections in rmarkdown?</a></p>