I was trying to create an rmarkdown file which dynamically loads a list of plotly objects with predefined comments. The minimal example code is listed below:
Currently, this chunk is failing at multiple levels:
1) plots do not show up properly - I tried to put htmltools::tagList(ls_ply)
at very end, it throws out an error.
2) I expected to make the comment as header, however, I know if I applied results='asis'
in chunk beginning, it would disable the plot.
```{r, echo=FALSE, message=FALSE}
library(plotly)
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
p1 <- qplot(carat, price, data=dsamp, colour=clarity)
art1 <- list(viz = p1, comment = 'article1')
p2 <- qplot(carat, price, data=dsamp, colour=carat)
art2 <- list(viz = p2, comment = 'article2')
ls_ply <- lapply(list(art1,art2),function(art){
cat('## ',art$comment,'\n')
art$viz
})
```