Title: | Add a Download Button to a 'shiny' Plot or 'plotly' |
---|---|
Description: | Add a download button to a 'shiny' plot or 'plotly' that appears when the plot is hovered. A tooltip, styled to resemble 'plotly' buttons, is displayed on hover of the download button. The download button can be used to allow users to download the dataset used for a plot. |
Authors: | Alex Pickering |
Maintainer: | Alex Pickering <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.4 |
Built: | 2024-11-01 03:38:48 UTC |
Source: | https://github.com/alexvpickering/shinydlplot |
Download button appears on hover in top right.
downloadablePlot(input, output, session, plot, filename, content, ...)
downloadablePlot(input, output, session, plot, filename, content, ...)
input , output , session
|
standard |
plot |
A |
filename |
A string of the filename, including extension, that the user's web browser should default to when downloading the file; or a function that returns such a string. (Reactive values and functions may be used from this function.) |
content |
A function that takes a single argument |
... |
additional named arguments passed to |
No return value, called to generate server logic.
downloadablePlotUI
, renderPlot
.
library(shiny) library(shinyjs) library(shinydlplot) library(ggplot2) ui <- fluidPage( useShinyjs(), downloadablePlotUI(id = 'iris_plot') ) server <- function(input, output, session) { plot <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point() callModule(downloadablePlot, id = 'iris_plot', plot = plot, filename = 'iris.csv', content = function(file) {write.csv(iris, file)}) } ## Not run: shinyApp(ui, server)
library(shiny) library(shinyjs) library(shinydlplot) library(ggplot2) ui <- fluidPage( useShinyjs(), downloadablePlotUI(id = 'iris_plot') ) server <- function(input, output, session) { plot <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length)) + geom_point() callModule(downloadablePlot, id = 'iris_plot', plot = plot, filename = 'iris.csv', content = function(file) {write.csv(iris, file)}) } ## Not run: shinyApp(ui, server)
Server-side logic for plotly with download data button in modebar
downloadablePlotly( input, output, session, plot, filename, content, title = "Download plot data" )
downloadablePlotly( input, output, session, plot, filename, content, title = "Download plot data" )
input , output , session
|
standard |
plot |
Object of class |
filename |
A string of the filename, including extension, that the user's web browser should default to when downloading the file; or a function that returns such a string. (Reactive values and functions may be used from this function.) |
content |
A function that takes a single argument |
title |
Text for plotly tooltip. |
No return value, called to generate server logic.
UI for plotly with download data button in modebar
downloadablePlotlyUI(id, width = "100%", height = "auto", inline = FALSE)
downloadablePlotlyUI(id, width = "100%", height = "auto", inline = FALSE)
id |
id string that gets namespaced by |
width , height
|
Must be a valid CSS unit (like |
inline |
use an inline ( |
an HTML tag object corresponding to the UI for downloadablePlotly
.
library(shiny) library(shinyjs) library(shinydlplot) library(plotly) ui <- fluidPage( useShinyjs(), downloadablePlotlyUI(id = 'iris') ) server <- function(input, output, session) { plot <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length) callModule(downloadablePlotly, id = 'iris', plot = plot, filename = 'iris.csv', content = function(file) {write.csv(iris, file)}) } ## Not run: shinyApp(ui, server)
library(shiny) library(shinyjs) library(shinydlplot) library(plotly) ui <- fluidPage( useShinyjs(), downloadablePlotlyUI(id = 'iris') ) server <- function(input, output, session) { plot <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length) callModule(downloadablePlotly, id = 'iris', plot = plot, filename = 'iris.csv', content = function(file) {write.csv(iris, file)}) } ## Not run: shinyApp(ui, server)
UI for plot with download data button
downloadablePlotUI( id, title = "Download plot data", width = "100%", height = "400px", zoom = FALSE )
downloadablePlotUI( id, title = "Download plot data", width = "100%", height = "400px", zoom = FALSE )
id |
id string that gets namespaced by |
title |
Text to display on hover of download button. |
width , height
|
Image width/height. Must be a valid CSS unit (like
|
zoom |
if |
an HTML tag object corresponding to the UI for downloadablePlot
.
NS
, downloadablePlot
, plotOutput