nbarrowman / vtree

An R package for calculating and drawing variable trees
https://nbarrowman.github.io/vtree
75 stars 6 forks source link

Shiny Outputs and add Interactivity with svg_pan_zoom.js #6

Closed trafficonese closed 4 years ago

trafficonese commented 4 years ago

I was playing with your repo and wanted to add some interactive functionality, as the variable trees can get quite big, which makes them unreadable. So Zooming in/out + panning would be nice.

I found this JS lib which offers this functionality for svg objects.

First off, I created some shiny functions: renderVtree and vtreeOutput. And there is a small example that you can run with:

library(shiny)
runApp(system.file("examples/shiny_app.R", package = "vtree"))

If you're up for that kind of interactivity, I would try to extend the function use_svgzoom (_its stored right now in /inst/examples/shiny_app.R_), so thats its the only function that has to be included if someone wants to make the tree more interactive. Somewhat similar to shinyjs::useShinyjs().

Additionally, I was also looking at the DiagrammeRcode for shiny widgets, because I would like to have the variable-tree clickable or brushable. That's why in the example there is an observeEvent for input$vtree_click, which works just locally on my computer for now. Since its still buggy, I wanted to rewrite the JS part and then upload a PR to DiagrammeR.

nbarrowman commented 4 years ago

Thanks, I'll take a look!

nbarrowman commented 4 years ago

That's very cool!