downloadablePlot: Server-side logic for plot with download data button

Description Usage Arguments Value See Also Examples

View source: R/downloadablePlot.R

Description

Download button appears on hover in top right.

Usage

1
downloadablePlot(input, output, session, plot, filename, content, ...)

Arguments

input

standard shiny boilerplate.

output

standard shiny boilerplate.

session

standard shiny boilerplate.

plot

A ggplot2 object or a function or reactive that generates a plot.

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 file that is a file path (string) of a nonexistent temp file, and writes the content to that file path. (Reactive values and functions may be used from this function.)

...

additional named arguments passed to renderPlot.

Value

No return value, called to generate server logic.

See Also

downloadablePlotUI, renderPlot.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)

shinydlplot documentation built on Dec. 3, 2020, 9:08 a.m.