问题
I would like to include a mermaid diagram in a PDF generated with R markdown.
According to this post, mermaid creates an HTML widget as output. Unfortunately, the answer provided there for xaringan slides does not work for PDFs generated in R markdown.
A Rmd-MWE is below. Any help is greatly appreciated!
---
title: "DiagrammeR: mermaid diagram in Rmd"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Simple mermaid diagram
```{r}
library(DiagrammeR)
mermaid("
graph LR
A-->B
", height = '100%', width = '100%')
```
回答1:
Here is a workaround. Replace the code in your last chunk with this:
library(DiagrammeR)
library(networkD3)
library(webshot)
g <- mermaid("
graph LR
A-->B
", height = '100%', width = '100%')
saveNetwork(g, "g.html")
webshot("g.html", "g.png", vheight = 50)
来源:https://stackoverflow.com/questions/60336847/diagrammer-mermaid-flowchart-in-rmarkdown-file-with-output-format-pdf-latex