I'm building a shiny app which initially will have 4 tabs, each with different plots. I'd like to give the user the option to download the plots as png or jpg files. Can't seem to get this working, as I can't really pass "file" to png() or jpg(). The reason why cannot download the plot because dat () is just the data frame, not the ggplot object. So, I suggest you store the plot and print it again in the downloadHandler. In the following code, I define a reactiveValues to store the ggplot object. library (shiny) library (reshape2) library (ggplot2) library (ggpubr) library (EnvStats) df. · Downloading data and plot is an important part of a shiny app when it comes to sharing the relevant data or plot as part of another presentation or analysis.
The shiny library and relevant data is first loaded; We define the server for the Shiny app as something with both objects that are input (from the ui.R) and output (from the server.R) We create a reactive Shiny plot that is output from server.R to ui.R with the function renderPlot. Example of a shiny app with data upload and different plot options. Raw. example.R. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters. Shiny has the ability to offer file downloads that are created on the fly, which makes it easy to build data exporting features. See here for an example app with file downloads. To run the example below, type: library (shiny) runExample ("10_download").
Value. A plot or image output element that can be included in a panel. Note. The arguments clickId and hoverId only work for R base graphics (see the graphics package). They do not work for grid-based graphics, such as ggplot2, lattice, and so on. Shiny: Download Plot. I am aware that this is a recurring question, but I must be drowning in a cup of tea. Have a look at the self-contained (a bit lengthy, admittedly) script below. Everything works like a charm apart from the capability to download the generated plot. I am positive the fix must be a one-liner, but so far no luck. R Shiny - Download plot demo. GitHub Gist: instantly share code, notes, and snippets.
0コメント