DiagrammeR/mermaid flowchart in Rmarkdown file with output format PDF/LaTex

梦想的初衷 提交于 2020-03-05 04:04:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!