rstudio / r2d3

R Interface to D3 Visualizations
https://rstudio.github.io/r2d3
Other
516 stars 105 forks source link

Debugging: Rstudio D3 Preview with Full R Code #81

Open ChrisWoodsSays opened 4 years ago

ChrisWoodsSays commented 4 years ago

I have some D3 code running from R (which creates and then provides the data to D3 using the data parameter) via R2D3 and its mostly working, but I need to use the browser console to understand what is happening with certain variables within the D3 element.

I can see the instructions below which show how to preview the D3 code from within Rstudio and a browser but the data passed is very simple, i.e.

// !preview r2d3 data=c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20)

https://rstudio.github.io/r2d3/articles/development_and_debugging.html

How do I run a more full R script to collate the data and import libraries (that are then referred to in dependencies) and then use R2D3 in such a way that I can use the browser debugger in a way similar to how the very simple example does.

jlfsjunior commented 3 years ago

I think that this package is no longer maintained, so you might not get an official reply from the development team.

I believe what you are asking is related to the usage of r2d3::r2d3 function, described here. r2d3 does some default data transformation from R to js, which is described in the documentation. I don't use the preview version, but I imagined it just something the "RStudio D3 preview add-on" uses to invoke the function I am pointing out.

As of using the browser developer tools for debugging, I recommend you to redefine console in javascript in order to log it there instead of using r2d3 default (that displays it in the browser window instead). This can be done (if el is your container element, svg or div) via:

var console = d3.window(el.node()).console;

Hope that can help!