本文介绍了在Rmarkdown中渲染高图列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成一个highcharts对象和选项卡的列表.然后,我想将其呈现为html页面.

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.

这里是一个例子:

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

我用knitr在RStudio中编译它.

I compile it in RStudio with knitr.

只有前两个选项卡具有图形,而后两个则没有...

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

我试图进行显式打印或显示,以在循环中添加\ n.没有运气.

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.

推荐答案

展开我的评论:您可以将每个out [[i]]项放在tagList中,然后打印出来.您的循环将变成

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

这篇关于在Rmarkdown中渲染高图列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:02
查看更多