Side effects of renderGrViz/grVizOutput not documented
ralmond opened this issue · comments
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.