Mermaid not rendering in Quarto document in RStudio IDE visual editor

I'm getting an error message when I try inserting a Mermaid code chunk into the RStudio IDE in a Quarto document. It's my understanding that Quarto has built-in support for Mermaid diagrams and it's built into the current version of RStudio IDE (I'm using the windows community version 2023.09.1 build 494 on an up-to-date Windows 11). Mermaid is one of the code chunk options.

The code chunk:
{mermaid}
graph LR
A-->B

produces the error message "'mermaid' is not recognized as an internal or external command, operable program or batch file."

FWIW the run code chunk icons do not appear in the upper right corner of the code chunk

I tried installing and loading DiagrammeR, which didn't help, although inserting the following R code chunk was an effective workaround.

{r}
library(DiagrammeR)
mermaid("
graph LR
A-->B
")

Is there an extension I'm supposed to install to get Mermaid to work?

This is working for me in html but not pdf.

---
title: "Mermaid"
author: "jrkrideau"
date: "`r Sys.Date()`"
date-format: iso
number-sections: true
format: html
---

```{r libraries}
#| label: setup 
#| include: false
#| eval: true
library(DiagrammeR)
```
“Arma virumque cano, Troiae qui primus ab oris Italiam, fato profugus, Laviniaque venit litora, multum ille et terris iactatus et alto vi superum saevae memorem Iunonis ob iram;”



```{r}
#| echo: false
mermaid("
graph LR
A-->B
")
```

@jrkrideau Thanks for the reply !

This is working ok, but uses DiagrammeR which is an R package and not the built-in support in Quarto. I'll add that to your answer.

Also, please see FAQ: How to Format R Markdown Source to learn how to format correctly raw markdown with chunks. I edited your post.

@lloydbrodsky what is your complete document ? This works ok

---
title: "Test"
format: html
keep-md: true
---

```{mermaid}
graph LR
A-->B
```

This is expected as the IDE does not know how to run those chunks, they are only evaluated in rendered and preview mode using Quarto but not in Notebook mode.

@jrkrideau Thanks for looking at this. As I mentioned the problem was that the IDE doesn't evaluate and render Mermaid chunks in Visual (preview) mode. In retrospect I assumed that if a particular chunk type (R, Mermaid, etc) was in the dropdown list (initiated by a '/') then it would be dynamically rendered. This is clearly wrong and the workaround is to write it up as an R chunk -- with diagrammeR for mermaid.

It occurs to me it might be worthwhile to give some visual indication someplace (such as, say, an asterisk on that dropdown or in documentation) on which are rendered dynamically and which not.

This would be great feedback for the RStudio IDE , both

  • The feature request of running mermaid somehow
  • The indication of what can be run and what not (but I believe there is already an arrow on cells that are runnable vs others).

Feedbacks lives in GitHub - rstudio/rstudio: RStudio is an integrated development environment (IDE) for R

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.