multiple (R) plotly figures generated in a Rmarkdown (knitr chunk) document
<p>I try to create multiple plotly figures in a Rmarkdown document using loop or lapply.</p>
<p>The R script:</p>
<pre><code>require(plotly)
data(iris)
b &lt;- lapply(setdiff(names(iris), c(&quot;Sepal.Length&quot;,&quot;Species&quot;)),
            function(x) {
              plot_ly(iris, 
                      x = iris[[&quot;Sepal.Length&quot;]],
                      y = iris[[x]], 
                      mode = &quot;markers&quot;)
            })
print(b)
</code></pre>
<p>works well, but it fails when included in a knitr chunk:</p>
<pre><code>---
output: html_document
---

```{r,results='asis'}
require(plotly)
data(iris)
b &lt;- lapply(setdiff(names(iris), c(&quot;Sepal.Length&quot;,&quot;Species&quot;)),
            function(x) {
              plot_ly(iris, 
                      x = iris[[&quot;Sepal.Length&quot;]],
                      y = iris[[x]], 
                      mode = &quot;markers&quot;)
            })
print(b)
```
</code></pre>
<p>I tried replacing <code>print(b)</code> with a combination of <code>lapply</code> <code>eval</code> and <code>parse</code> but only the last figure was displayed.</p>
<p>I suspect a scoping/environment issue but I cannot find any solution.</p>