Creates a custom plot output that is paired with a linked downloadFile button. This module is compatible with ggplot2, grob and lattice produced graphics.
downloadablePlotUI(
id,
downloadtypes = c("png"),
download_hovertext = NULL,
width = "100%",
height = "400px",
btn_halign = "right",
btn_valign = "bottom",
btn_overlap = TRUE,
clickOpts = NULL,
hoverOpts = NULL,
brushOpts = NULL
)
character id for the object
vector of values for download types
download button tooltip hover text
plot width (any valid css size value)
plot height (any valid css size value)
horizontal position of the download button ("left", "center", "right")
vertical position of the download button ("top", "bottom")
whether the button should appear on top of the bottom of the plot area to save on vertical space (there is often a blank area where a button can be overlayed instead of utilizing an entire horizontal row for the button below the plot area)
NULL or an object created by the clickOpts function
NULL or an object created by the hoverOpts function
NULL or an object created by the brushOpts function
list of downloadFileButton UI and plot object
downloadFile button will be hidden if downloadablePlot
parameter downloadfxns
or
downloadablePlotUI
parameter downloadtypes
is empty
downloadablePlotUI("myplotID", c("png", "csv"),
"Download Plot or Data", "300px")
When there is nothing to download in any of the linked downloadfxns the button will be hidden as there is nothing to download.
This module is NOT compatible with the built-in (base) graphics (such as basic plot, etc.) because they cannot be saved into an object and are directly output by the system at the time of creation.
Call this function at the place in ui.R where the plot should be placed.
Paired with a call to downloadablePlot(id, ...)
in server.R
if (interactive()) {
library(shiny)
library(ggplot2)
library(periscope2)
shinyApp(ui = fluidPage(fluidRow(column(width = 12,
downloadablePlotUI("object_id1",
downloadtypes = c("png", "csv"),
download_hovertext = "Download plot and data",
height = "500px",
btn_halign = "left")))),
server = function(input, output) {
download_plot <- function() {
ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_point(aes(color = cyl)) +
theme(legend.justification = c(1, 1),
legend.position = c(1, 1),
legend.title = element_blank()) +
ggtitle("GGPlot Example ") +
xlab("wt") +
ylab("mpg")
}
downloadablePlot(id = "object_id1",
logger = "",
filenameroot = "mydownload1",
downloadfxns = list(png = download_plot, csv = reactiveVal(mtcars)),
aspectratio = 1.33,
visibleplot = download_plot)
})
}