How to implement interactive graph from plotly in overleaf? - graph

I want to implement interactive graph from plotly in overleaf. However, overleaf removed the communication with plotly in the V2 version. Is it still possible somehow to implement interactive graph in overleaf and therefore in pdf?
I want to hide/unhide line, zoom in and see value of different points when clicking on it.
I saw this question a couple times before, but the answere was only to zoom in or use javascript and implementing different picture on top of eachother.
However, this is not what i am looking for. I am looking for a really interactive in PDF. Does somebody know how this is possible?

Related

Is it possible to show a plot in the hover info using plotly in R?

Suppose I have a plotly graph in which I want to show another plot as hover info. Is it possible using plotly or echart4r? If yes, an example would be really appreciated.
It's certainly not a straightforward solution but this should be achievable using Shiny.
Plotly has the event_data function to allow you to access information about the user's interaction with the plot (such as where they are hovering):
https://rdrr.io/cran/plotly/man/event_data.html
https://plotly-r.com/linking-views-with-shiny.html#shiny-plotly-inputs
You could then tie this to a reactive UI element which contains the plot you are after inside of a tooltip. You will likely need to use a bit of Javascript to move around the tooltip. See example 3 from here for an idea:
https://stackoverflow.com/a/38919892/2947600
Give this a go if you'd like and if you're having a hard time, I might have the time to make a minimal example.

How to keep camera orientation fixed in an interactive 3D plot in R/Shiny

I have a 3D rgl plot that users can modify based on some inputs (you can see it in action at https://magalab.shinyapps.io/rgl_test/). But every time the user modifies the input settings, renderer returns to the initial orientation to redraw the model. I want to keep the orientation consistent between updates. I know how to do that in rgl, and there is already another similar question
(Shiny RGL Plot3D: Keep Plot View Orientation On Replot), which did not receive any answer.
There is potentially a relevant topic at shiny app rglwidget get userMatrix to generate another plot with same rotation, but I don't want to see the userMatrix, simply pass it to the open3d().
Unfortunately, I am not familiar with Javascript and Shiny to achieve this. Any pointers will be much appreciated.
In the very newest rgl (version 0.99.18, currently only on R-forge), there's a function called shinyGetPar3d that is designed to do what you want. See example(shinyGetPar3d) for a demonstration of how to use it.

How to show an iplot without opening an additional window into r shiny

I'm trying to build interactive graphs in my shiny app. The user should be able to click on bars and see where the cases are displayed in another graph for example like a scatterplot next to the barplot.
There are different r packages, that are doing a great job: iplot, rggobi, acinonyx. I also found qtlcharts, but it does not exactly what I wanted. The problem is, I can't figure out, how to integrate different iplots into my shiny app boxes. Is there any way preventing iplots from opening separate windows for the graphs?
In acinonyx you can say window=FALSE, which prevents opening the java window of the graph. But the graph isn't displayed in the box as well. You could add/move the iplot into icontainer, iVisual or iWindow, but none of them can be integrated into the shiny boxes in the ui without printing the error: unsupported data frame or doing nothing at all.
I found the answer to my question: building reactive ggplots in shiny and adding coloured layers to one plot if the other plot is clicked will do the job.

Rottation of R 3d plots not working properly with knitr and webgl

I am trying to use rgl knitr and webgl to plot several interactive 3d plots in a sequence.
And I am getting quite a weird behavior: when trying to rotate the plots with a mouse they seem to get back to their initial position after each mouse drag. This makes the interaction quite unintuitive. I noticed that the last plot on a page is not affected by this, but all the rest are.
This can be seen on the original knitr example:
source: https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.Rmd
plots: https://dl.dropboxusercontent.com/u/15335397/misc/webgl-rmd.html
Notice the differences when trying to rotate the first and second figure.
What could be a potential cause? Maybe the problem can be solved by passing some additional parameters to the 3d and rgl plots (was not able to find any)? Or is it a minor bug of knitr and webgl?
This is a bug in knitr, and has been fixed in the development version. The reason for it is that rgl includes <script src="CanvasMatrix.js" type="text/javascript"></script> for every plot, even when there are multiple plots on the same page. I have removed this line on knitr's side, so that CanvasMatrix.js is only loaded once. The knitr example you mentioned works now.

Can R create a barplot image with clickable bars to insert on a webpage?

I know how to create a barplot, and how to stick it on a webpage; e.g, using hwriteImage in the hwriter package.
What I'd like is for each bar to be a region which highlights on mouseover, and where each bar has a different link when clicked. Similar to this map of the U.S. using the jQuery maphilight plugin, but for a barplot rather than a map. I imagine R could calculate the coordinates of the regions around each bar, generate the HTML AREA tag etc and pass this to maphilight quite easily. Has it been done already? I searched but no luck so far.
Have a look here, which summarises a couple of methods: rggobi and iplots. rggobi looks pretty promising, though maybe the installation looks a bit involved. iplots is only good for scatter plots.
Some other options (I think these are strongest ones at the moment):
googleVis
The googleVis package interfaces with the google charts API: try demo(googleVis) and the third & fourth one are bar chart (there could be more). It has the advantage of being pretty simple to get started with, although these are not R graphics:
df=data.frame(country=c("US", "GB", "BR"), val1=c(10,13,14), val2=c(23,12,32))
Column <- gvisColumnChart(df)
plot(Column)
gridSVG
The gridSVG exports the current grid graphics to an .svg file that can be included into a webpage. Unlike googleVis, it's R graphics (so you can use grid/ggplot2 which are more familiar). It looks like you may have to know some Javascript to further embellish your plots though (e.g. to animate on mouse over, you use grid.garnish(...,onmouseover=...)).
There's some example code you can try here (The really awesome ones are here - usually clicking on the "SVG file" link will have the full interactivity/animation.) (This one is a scatterplot where the points highlight when you move your mouse over them).
As I said - have a look at the package pages, demos, examples, etc to see which suits you.

Resources