Skip to content

Update to D3 v4 to combine netword3D and mermaid in Rmarkdown #232

@ekstroem

Description

@ekstroem

This is essentially a repost of this question on Stack Overflow which I also raised as an issue with the htmlwidgets package.

I would like to include two htmlwidgets in the same Rmarkdown document - a mermaid flowchart from the DiagrammeR package and a network3D graph. If I include both in my document then none of them renders but if I only include one of them then it will be rendered.

Here's a minimal example in Rmarkdown that shows the problem

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

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## The grViz always works

```{r dia1, echo=FALSE}
library(DiagrammeR)
grViz("
  digraph {
    layout = twopi
    A -> {B C D}
  }")
```

# From here onwards I can only include one of the two graphs 

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

# Plot

```{r}
library(networkD3)
Source <- c("A", "A", "A", "A", "B", "B", "C", "C", "D")
Target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
NetworkData <- data.frame(Source, Target)

# Create graph
simpleNetwork(NetworkData)
```

If I add multiple DiagrammeR graphs based on grViz then all is fine and dandy. Also if I leave out the mermaid plot then I'll see the remaining two. Are they not supposed to play together nicely? I've tried to swap the ordering of the library calls to no avail.

ramnath told me that

networkD3 uses D3 v 4, while diagrammeR uses D3 v 3. D3 v 4 introduced a lot of breaking
changes in the API. This is the reason these two widgets are not playing nicely. You can ping the author of diagrammeR to see if he can update it to using D3 v 4.

so ... any plans for upgrading to D3 v4?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions