Search code examples
rr-markdowndiagrammermermaid

How to include DiagrammeR/mermaid flowchart in a Rmarkdown file


I have an R markdown file:

---
title: "Untitled"
author: "Me"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. 

As well as a DiagrammeR/mermaid chart:

graph LR
    A-->B

How can I add the chart in the R-markdown?


Solution

  • Actually it is trivial:

    ---
    title: "Untitled"
    author: "Me"
    output: html_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    ## R Markdown
    This is an R Markdown document. 
    
    ```{r}
    library(DiagrammeR)
    mermaid("
    graph LR
        A-->B
    ")
    ```