How to download rCharts plots in shiny with downloadHandler - r

In shiny apps ggplot2 graphs can easily be downloaded based on the downloadHandler function. Is it possible to download the javascript visualisations that are produced by means of rCharts in a similar way? If yes, what is the best approach?

If you use the HighCharts capability of rCharts then you can use it's exporter feature which has an download capability as demonstrated here (source).
If not, you're left with DOM introspection like I ended up using here. That has no R behind it, but it shows how to find the SVG in the DOM and make it so the graphic is exportable in a couple different ways.

Related

How to download shiny graph in PDF Formart

I am new to R programming. I have developed a shiny dashboard application for different visualization purposes where I am plotting various graphs with the help of renderDataTable, renderPlot, renderRpivotTable, renderImage renderInfoBox.
But I am unable to figure out what is the best way to download these graphs/charts/table/infobox in PDF format.
So for I am rendering Rmarkdown within downloadHandler to achieve this requirement. But It is not working for every plot such renderInfoBox,renderDataTable. I will highly appreciate any inputs on this.

How can I build Shiny applications with Animation in R?

I am trying to build a shiny app to build interactive animations with R. I currently have a function that can build gifs/other output options using the Animation package(http://cran.r-project.org/package=animation) that loops through a series of ggplots(by date). And also a shiny app that can show a single ggplot based on the selected date.I want to build a shiny app that refreshes an animation based on a selected date range.
Are there examples of code that uses maybe saveHTML with UIoutput in Shiny? Would this be possible?
reset animation in Shiny R Studio shows someone trying to build an animation within Shiny. https://gist.github.com/yihui/5899181 is example of integrating a saveGIF function into a shiny app, but that is through a download.
Alternative suggestions/packages I could look at to approach this problem in R not necessarily using Animation and/or Shiny would also be appreciated.
I suggest using the googleVis package --> the tool, gvisMotionchart. It's really simple to work with, just make sure your data is numeric or time oriented in some way and also have some character/categorical variable to plot as circles. Best of all is that all animation tools are ALREADY included inside the motion chart.
If you want details how to create this, here is a model example of how to detailed in this thread.
Chart not generated in R shiny when run locally using googleVis
Here's a screenshot of an example of one I've created to visualize chess data.
googlevis example

Sparklines in Shiny using gvisTable

I would like to display sparklines in tables Shiny displays, using gvisTable from the googleVis package.
My question is related to this one:
How does one include sparklines and other per-row graphics in a Google Table (or similar)?
For which there is an accepted answer for the javascript version. However, I am not sure how to implement this solution within Shiny.

Non-interactive GoogleVis charts

Is it possible for googleVis Package from R to generate Images as oppose to interactive charts? To create a GoogleVis Chart in R:
library(googleVis)
M <- gvisMotionChart(Fruits, "Fruit", "Year")
plot(M)
This initiates a browser and then it will plot an interative chart. Is there a way such that I can create a non-interactive image and plot it in R
What I have done is a complete hack, but it works. I view the HTML for the googleVis object generated and extract the svg. I save the svg as a file and open it in an image editor that can open and convert svg files.
There's no real need to use googleVis for this. If you create your plot in ggplot2, the ggthemes add-on package has theme_gdocs(), and associated colour palettes that will let you style your chart exactly like a Google Chart.
It looks like the only way to do this is to make the interactive plot, and take a screenshot. The object returned by googleVis is a Flash application embedded in html, I think you probably cannot expect it to give a static plot!
Some hacks I found that could potentially be able to convert gvis charts to images:
http://html2canvas.hertzen.com/
https://gist.github.com/battlehorse/1333906

Is there a way to create interactive plots (a la D3) in IPython notebooks?

I found those two answers:
Animated graphs in ipython notebook ,
How to grab matplotlib plot as html in ipython notebook?
But they don't address interactivity. I would like to display a plot with 2-3 curves and let the user hover those curves to receive more details or control the parameters that are used to generate those curves from a combo-box
check the following answer at iPython: Manipulate-like command.
as well as the two following directions:
IPython interact/ive as motivated in IPython - The Attributes ofSoftware and How They Affect Our Work - Brian Granger near 32m:12s; and available at IPython's github
Altair provides a powerful and succinct syntax, based on vega-lite; see the gallery
MPLD3: Bringing Matplotlib to the Browser
I don't believe the standard matplotlib plots are capable of the interactivity you want. Chaco can do interactive graphs, but not in an ipython notebook, AFAICT. Your best bet is probably Bokeh. It outputs to Javascript/HTML, can do interactive graphs, and has an example of using it from ipython.
You may want to check out Plotly. They render interactive D3 plots inside IPython Notebooks (examples here. You can export as static images as well, and zoom, hover, pan, and see text on the hover. Interactivity is one of the pitches they're emphasizing. For more, you can also use IPython widgets inside the Notebook, which gives you more control and options. For example:
Like #AFoglia, I'm going to suggest other libraries that might be what you're looking for: Tangle, Mathematica Notebooks, IPython / Bokeh, RactiveJS, or ReactJS.
Another solution might be the Charts library. It enables you to use the excellent Highcharts javascript library to make beautiful and interactive plots out of the box.
Some features:
Vector plots which you can download in .png, .jpg and .svg formats so you will never run into resolution problems.
Interactive charts (zoom, slide, hover over points, ...)
Usable in an IPython notebook
Explore hundreds of data structures at the same time using the asynchronous plotting capabilities.
Disclaimer: I'm the developer of the library
You can run javascript straight from IPython notebooks (%%html and %%javascript), so it should be possible to run D3 code. Check this video. The exact way in which this would be implemented is not set in stone yet, as this is a feature for IPython 2.0. There are many hacks available as of now, as well as projects that try to port some characteristics of D3 to Python (such as bokeh and python-nvd3).
I have not yet tested any of these. My own bias would be to try the example below first, which is static, but uses D3 directly (so it should theoretically work for interactive plots):
gist
notebook
Other answeres here seem to be outdated. IPython 2.0 has support for interactive widgets. Read the docs including some examples, but note that the nbviewer.ipython.org does not show the interactive widgets. Copy & pasting the examples to try.jupyter.org works.

Resources