xloki
xloki

Reputation: 13

Render a list of highcharts in Rmarkdown

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.

Upvotes: 1

Views: 1089

Answers (1)

user2554330
user2554330

Reputation: 44788

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]]))
}

Upvotes: 1

Related Questions