Render a list of highcharts in Rmarkdown

久未见 提交于 2021-02-08 07:29:32

问题


I generate a list of highcharts objects and tabs. Then I'd like to render it into an html page.

I can't figure out how to do it in a simple loop.

If i do it one by one it works, but not in a for.

Here is an example :

---
output: 
  html_document
---

``` {r, echo=FALSE, results='asis'}
library(highcharter)

out<-list(gr1=highcharts_demo(),gr2=highcharts_demo())

cat("

Column {.tabset}
-----------------------------------------------------------------------

")

cat("

###A1

"
)
out[[1]]

cat("

###A2

"
)
out[[2]]

for (i in c(1,2) )
{
  cat(paste0("

###","B",i,"

"
))
  out[[i]]
}
```

I compile it in RStudio with knitr.

And only the first two tabs have graphs, not the last two...

I tried to put explicit print or show, to add a \n in the loop. No luck.

Any idea ? Thanks a lot for your help.


回答1:


To expand on my comment: you can put each out[[i]] item in a tagList, and print it. Your loop would become

for (i in c(1,2) )
{
  cat(paste0("

###","B",i,"

"
))
  print(htmltools::tagList(out[[i]]))
}


来源:https://stackoverflow.com/questions/44136572/render-a-list-of-highcharts-in-rmarkdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!