rich-iannone / DiagrammeR

Graph and network visualization using tabular data in R
https://rich-iannone.github.io/DiagrammeR/
Other
1.68k stars 247 forks source link

Side effects of renderGrViz/grVizOutput not documented #472

Open ralmond opened 1 year ago

ralmond commented 1 year ago

Creating an output using grVizOutput and then assigning the output of renderGrViz in addition to rendering the graph, also creates input elements. This side effect is not really documented anywhere that I can see, so developers can't use it.

ui <- fluidPage(
   #...
   grVizOutput("graph")
  #...
)

server <- function (input, output) {
  output$graph <- renderGrViz({grViz("digraph ...")})
  #...
}

Will, in addition to rendering the graph, create a reactive element input$graph_click. This appears to be a list with elements nodeValues and id.

Here is the relevant Javascript code from DiagrammeR.js (starting at line 135)

 $("#" + id + " .node").click(function(e) {
          // Build return object *obj* with node-id and node textContent
          var obj = {
            id: e.currentTarget.id,
            nodeValues: e.currentTarget.textContent
          };
          // Send *obj* to Shiny's inputs (input$[id]+_click  e.g.: input$vtree_click))
          Shiny.setInputValue(id + "_click", obj, {priority: "event"});
        });

I gather that these represent the id and label of the nodes, but this is a guess.

Really, documentation needs to be added to the renderGrViz and grVizOutput functions so that this behavior is well specified.

This issue gives a functioning example.

https://github.com/rich-iannone/DiagrammeR/issues/402