Interactive Plotting
I’ve been getting familiar with ggplot
in R for generating figures while
working on a PLDI submission. I spent a bit of time messing around with
styling and have grown increasingly disappointed that I can’t include
interactive plots in PDF submissions :/. Fortunately, Web browsers are much
more featureful, and I’d like to incorporate some interactivity into my
technical posts moving forwards.
It works! Sort of…
First, I have a couple requirements I would like to satisfy.
- Figures should be generated from R code. I don’t want to have to do data processing in JavaScript.
- Graphs and figures should be responsive to user input, and offer the ability to “dig in” to the results for more details.
- Interactive plots should work entirely client-side. I don’t want to host a server, or deploy to a third party.
- Developing interactive posts should integrate cleanly with my GitHub Pages deployment process. Specifically, plots should be embeddable within Markdown posts as inline HTML.
Here’s what I’ve managed to get working so far. This page embeds a
Plotly widget as a JavaScript data URL within an
iframe
.
Some Future Ideas
This current approach is slooow. I’d like plots to load asyncrhonously without blocking the page. Ideally, plots would load quick enough that blocking is a non-issue. I think I can get this working better with some JavaScript hacking on my own. The current solution is pretty naive, and simply exports Plotly figures to JavaScript programs from R Studio. If anyone has experience with this I’d love some help in optimizing the process/end result!