Add a Download Button to a 'shiny' Plot or 'plotly'

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.


shinydlplot

Installation

remotes::install_github('alexvpickering/shinydlplot)

Usage

Example that renders a plotly with a download button to download the iris dataset:

library(shiny)
library(shinyjs)
library(shinydlplot)
library(plotly)

ui <- fluidPage(
  useShinyjs(),
  downloadablePlotlyUI(id = 'iris_plotly')
)

server <- function(input, output, session) {
  
  plot <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
  
  callModule(downloadablePlotly, 
             id = 'iris_plotly', 
             plot = plot, 
             filename = 'iris.csv', 
             content = function(file) {write.csv(iris, file)})
}

shinyApp(ui, server)

downloadable plotly

Example that renders a ggplot2 object with a download button to download the iris dataset:

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)})
}

shinyApp(ui, server)

downloadable plot

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("shinydlplot")

0.1.4 by Alex Pickering, 4 years ago


Browse source code at https://github.com/cran/shinydlplot


Authors: Alex Pickering


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports shinyBS, shiny, shinyjs, plotly, htmlwidgets, htmltools, methods, utils

Suggests ggplot2


See at CRAN