Interactive graphviz in Shiny, via r2d3 ... help with javascript dependencies

Greetings...

I'm working with a goal of being able to dynamically interact with graphviz plots in a Shiny app.

I got basic r2d3 examples running without any trouble.

But to fully do the above, I think I need some additional library code. d3-graphviz appears to have the functionality I might need to do this:
https://github.com/magjac/d3-graphviz

What I don't know how to do is include the d3-graphviz dependency in my code. Unfortunately I'm completely new to javascript and I can't figure out the right syntax to express it ... perhaps it uses htmlDependency()?

ui <- fluidPage(
  d3Output("d3")
)

server <- function(input, output) {
  output$d3 <- renderD3({
    r2d3(
      script = "gv1.js"
   ###   , dependencies = {{Here's where I need help}}  ####
    )
  })

When I look at d3-graphiz examples in javascript, they look like:

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v4.min.js"></script>
<script src="https://unpkg.com/viz.js@1.8.1/viz.js" type="javascript/worker"></script>
<script src="https://unpkg.com/d3-graphviz@2.6.1/build/d3-graphviz.js"></script>
<div id="graph" style="text-align: center;"></div>
<script>

d3.select("#graph").graphviz()
    .graphviz
    .renderDot('digraph  {a -> b}');

</script>

(see https://bl.ocks.org/magjac/a23d1f1405c2334f288a9cca4c0ef05b)

Can anyone provide any guidance about how to inject those

<script src=...> 

into my Shiny app, so that it recognizes d3-graphviz?

Thanks,
Greg

Yea, the dependencies argument expects a list of htmltools::htmlDependency() objects. If you want, you can have those dependencies use external links like this:

library(htmltools)

deps <- list(
  htmlDependency(
    name = "d3",
    version = "4.0",
    src = list(href = "https://d3js.org/"),
    script = "d3.v4.min.js"
  ),
  htmlDependency(
    name = "viz.js",
    version = "1.8.1",
    src = list(href = "https://unpkg.com/viz.js@1.8.1"),
    script = "viz.js"
  ),
  htmlDependency(
    name = "d3-graphviz",
    version = "2.6.1",
    src = list(href = "https://unpkg.com/d3-graphviz@2.6.1"),
    script = "build/d3-graphviz.js"
  )
)

r2d3(..., dependencies = deps)

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