Reputation: 1165
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%')
```
Upvotes: 7
Views: 3743
Reputation: 46
Run these two lines in your Rstudio console:
install.packages('webshot')
webshot::install_phantomjs()
https://bookdown.org/yihui/bookdown/html-widgets.html
Upvotes: 3
Reputation: 30445
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)
Upvotes: 1