Package 'shinydlplot'

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

Help Index


Server-side logic for plot with download data button

Description

Download button appears on hover in top right.

Usage

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

Arguments

input, output, 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

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

Description

Server-side logic for plotly with download data button in modebar

Usage

downloadablePlotly(
  input,
  output,
  session,
  plot,
  filename,
  content,
  title = "Download plot data"
)

Arguments

input, output, session

standard shiny boilerplate.

plot

Object of class 'plotly' or a function or reactive that generates one.

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

title

Text for plotly tooltip.

Value

No return value, called to generate server logic.

See Also

downloadablePlotlyUI


UI for plotly with download data button in modebar

Description

UI for plotly with download data button in modebar

Usage

downloadablePlotlyUI(id, width = "100%", height = "auto", inline = FALSE)

Arguments

id

id string that gets namespaced by shiny::NS.

width, height

Must be a valid CSS unit (like "100%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended. Note that, for height, using "auto" or "100%" generally will not work as expected, because of how height is computed with HTML/CSS.

inline

use an inline (span()) or block container (div()) for the output

Value

an HTML tag object corresponding to the UI for downloadablePlotly.

See Also

NS, downloadablePlotly

Examples

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

Description

UI for plot with download data button

Usage

downloadablePlotUI(
  id,
  title = "Download plot data",
  width = "100%",
  height = "400px",
  zoom = FALSE
)

Arguments

id

id string that gets namespaced by shiny::NS.

title

Text to display on hover of download button.

width, height

Image width/height. Must be a valid CSS unit (like "100%", "400px", "auto") or a number, which will be coerced to a string and have "px" appended. These two arguments are ignored when inline = TRUE, in which case the width/height of a plot must be specified in renderPlot(). Note that, for height, using "auto" or "100%" generally will not work as expected, because of how height is computed with HTML/CSS.

zoom

if TRUE brush then double-click to zoom.

Value

an HTML tag object corresponding to the UI for downloadablePlot.

See Also

NS, downloadablePlot, plotOutput