我想动态生成标签,并且每个标签都绘制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只是为了简单起见,我使用的一些diadiag图。然后创建一个选项卡
## 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(chorddiag(m))
cat( '\n\n')
}
```
在Rmarkdown窗口中,一切工作都很好,但是当我打结时,我无法生成图。我也尝试使用htmltools :: tagList,因为它确实适用于plotly库,它确实创建了一个空间,但是没有显示图
我也收到错误:/chunk_output/42CC8C6564F105CC/4A1ED7C7/c3rny570vwpsr/000029.html?viewer_pane=1&capabilities=1 not found
尝试一下。解决方案与您以前的问题相同。 (;决定性的步骤是在循环外部添加“虚拟”图。根据此post,需要使用此虚拟图以确保在渲染的HTML中包含库(在本例中为d3):
---
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 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(chorddiag(m)))
cat( '\n\n')
}
```