0

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

broti
  • 1,338
  • 8
  • 29
  • 1
    The mermaid creates a htmlwidget as output. Perhaps you could wrap it into a – user12728748 May 02 '20 at 11:02

1 Answers1

1

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

mysteRious
  • 4,102
  • 2
  • 16
  • 36