rdiagrammerrpres

Mermaid (diagrammeR) graph not displayed in RPres


I am trying to include a graph built with the diagrammeR package in an RPres. That's the graph:

library(DiagrammeR)
mermaid("graph TD
          X1(X1)-->Z1(Z2)
          X2(X2)-->Z2(Z2)
          X1(X1)-->Z2(Z2)
          Z1(Z1)-->Y(Y)
          Z2(Z2)-->Y(Y)
            ")

Looking at the output in RStudio's viewer pane is no problem. No I include it in an RPres:

Untitled
========================================================
author: 
date: 
autosize: true

First Slide
========================================================

```{r,echo=FALSE, results = "asis"}

library(DiagrammeR)
mermaid("graph TD
          X1(X1)-->Z1(Z2)
          X2(X2)-->Z2(Z2)
          X1(X1)-->Z2(Z2)
          Z1(Z1)-->Y(Y)
          Z2(Z2)-->Y(Y)
            ")

(note that the "```" to close the code chunk aren't displayed here because of markup...)

Alas, nothing but the abyss of emptiness:

enter image description here


Solution

  • Are you committed to RPres or would you consider alternative slide formats? For example, if you create a new R Markdown document and specify output: ioslides_presentation in the YAML header, the diagram will render properly:

    ---
    title: "Untitled"
    author: "Your Name"
    date: "5/2/2020"
    output: ioslides_presentation
    ---
    
    Untitled
    ===========================================================
    Here is the content for the second slide in different style
    
    
    ## Title of Mermaid Slide
    
    ```{r,echo=FALSE, results = "asis"}
    
    library(DiagrammeR)
    mermaid("graph TD
              X1(X1)-->Z1(Z2)
              X2(X2)-->Z2(Z2)
              X1(X1)-->Z2(Z2)
              Z1(Z1)-->Y(Y)
              Z2(Z2)-->Y(Y)
            ")
    

    Which produces this:

    enter image description here