使用动态生成的选项卡时如何显示 chorddiag plot 列表?
How to display a list of chorddiag plot swhen using dynamically generated tabs?
我想动态生成标签,每个标签绘制corddiag
图
library(igraph)
library(tidygraph)
library(chorddiag)
m <- matrix(c(11975, 5871, 8916, 2868,
1951, 10048, 2060, 6171,
8010, 16145, 8090, 8045,
1013, 990, 940, 6907),
byrow = TRUE,
nrow = 4, ncol = 4)
groupnames <- c("black", "blonde", "brown", "red")
row.names(m) <- groupnames
colnames(m) <- groupnames
m 只是我为了简单起见而使用的一些 corddiag
图。
基于不同的数据集,我在每一页上都有不同的图表。所以我在下一步中创建了一个 corddiag
图列表:
```{r, include=FALSE}
graphList_biling.lan <- list()
for ( i in 1:3) {
graphList_biling.lan[[i]] <- htmltools::tagList(chorddiag(m))
}
```
为了简单起见,我只是在每个循环中使用相同的 m
,但在我的实际情节中它们会有所不同,这就是为什么我需要创建一个列表。然后我执行以下操作:
## First learned languages {.tabset .tabset-fade .tabset-pills}
```{r echo=FALSE, fig.height=6, fig.width=6, warning=FALSE, results='asis'}
for (i in 1:3) {
cat("###", paste("Tab ",i), '{-}', '\n\n')
print(htmltools::tagList( graphList_biling.lan[[i]]))
cat( '\n\n')
}
```
在 Rmarkdown window 中一切都很好,但是当我打结时我无法生成图。它确实创建了一个 space 但没有显示任何图
试试这个。解决方案与您之前的问题相同。 (; 决定性的一步是在循环外添加一个 "dummy" 图。根据这个 post 需要这个虚拟图来确保库(在本例中为 d3)包含在呈现的 HTML:
---
title: "test_tab_loop"
date: "26 5 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(igraph)
library(tidygraph)
library(chorddiag)
m <- matrix(c(11975, 5871, 8916, 2868,
1951, 10048, 2060, 6171,
8010, 16145, 8090, 8045,
1013, 990, 940, 6907),
byrow = TRUE,
nrow = 4, ncol = 4)
groupnames <- c("black", "blonde", "brown", "red")
row.names(m) <- groupnames
colnames(m) <- groupnames
```
## First learned languages {.tabset .tabset-fade .tabset-pills}
```{r, include=FALSE}
## init step: takes care that the libs are included
htmltools::tagList(chorddiag(m))
```
```{r, include=FALSE}
graphList_biling.lan <- list()
for (i in 1:3) {
graphList_biling.lan[[i]] <- htmltools::tagList(chorddiag(m))
}
```
## First learned languages {.tabset .tabset-fade .tabset-pills}
```{r echo=FALSE, fig.height=6, fig.width=6, warning=FALSE, results='asis'}
for (i in 1:3) {
cat("###", paste("Tab ",i), '{-}', '\n\n')
## You already applied htmltools::taglist. So just print
print(graphList_biling.lan[[i]])
cat( '\n\n')
}
```
我想动态生成标签,每个标签绘制corddiag
图
library(igraph)
library(tidygraph)
library(chorddiag)
m <- matrix(c(11975, 5871, 8916, 2868,
1951, 10048, 2060, 6171,
8010, 16145, 8090, 8045,
1013, 990, 940, 6907),
byrow = TRUE,
nrow = 4, ncol = 4)
groupnames <- c("black", "blonde", "brown", "red")
row.names(m) <- groupnames
colnames(m) <- groupnames
m 只是我为了简单起见而使用的一些 corddiag
图。
基于不同的数据集,我在每一页上都有不同的图表。所以我在下一步中创建了一个 corddiag
图列表:
```{r, include=FALSE}
graphList_biling.lan <- list()
for ( i in 1:3) {
graphList_biling.lan[[i]] <- htmltools::tagList(chorddiag(m))
}
```
为了简单起见,我只是在每个循环中使用相同的 m
,但在我的实际情节中它们会有所不同,这就是为什么我需要创建一个列表。然后我执行以下操作:
## First learned languages {.tabset .tabset-fade .tabset-pills}
```{r echo=FALSE, fig.height=6, fig.width=6, warning=FALSE, results='asis'}
for (i in 1:3) {
cat("###", paste("Tab ",i), '{-}', '\n\n')
print(htmltools::tagList( graphList_biling.lan[[i]]))
cat( '\n\n')
}
```
在 Rmarkdown window 中一切都很好,但是当我打结时我无法生成图。它确实创建了一个 space 但没有显示任何图
试试这个。解决方案与您之前的问题相同。 (; 决定性的一步是在循环外添加一个 "dummy" 图。根据这个 post 需要这个虚拟图来确保库(在本例中为 d3)包含在呈现的 HTML:
---
title: "test_tab_loop"
date: "26 5 2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(igraph)
library(tidygraph)
library(chorddiag)
m <- matrix(c(11975, 5871, 8916, 2868,
1951, 10048, 2060, 6171,
8010, 16145, 8090, 8045,
1013, 990, 940, 6907),
byrow = TRUE,
nrow = 4, ncol = 4)
groupnames <- c("black", "blonde", "brown", "red")
row.names(m) <- groupnames
colnames(m) <- groupnames
```
## First learned languages {.tabset .tabset-fade .tabset-pills}
```{r, include=FALSE}
## init step: takes care that the libs are included
htmltools::tagList(chorddiag(m))
```
```{r, include=FALSE}
graphList_biling.lan <- list()
for (i in 1:3) {
graphList_biling.lan[[i]] <- htmltools::tagList(chorddiag(m))
}
```
## First learned languages {.tabset .tabset-fade .tabset-pills}
```{r echo=FALSE, fig.height=6, fig.width=6, warning=FALSE, results='asis'}
for (i in 1:3) {
cat("###", paste("Tab ",i), '{-}', '\n\n')
## You already applied htmltools::taglist. So just print
print(graphList_biling.lan[[i]])
cat( '\n\n')
}
```