Description Usage Arguments Examples
View source: R/shinywrappers.R
Allows content from the Shiny application to be made available to the user as
file downloads (for example, downloading the currently visible data as a CSV
file). Both filename and contents can be calculated dynamically at the time
the user initiates the download. Assign the return value to a slot on
output
in your server function, and in the UI use
downloadButton
or downloadLink
to make the
download available.
1 | downloadHandler(filename, content, contentType = NA, outputArgs = list())
|
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 |
contentType |
A string of the download's
content type, for
example |
outputArgs |
A list of arguments to be passed through to the implicit
call to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
downloadLink("downloadData", "Download")
)
server <- function(input, output) {
# Our dataset
data <- mtcars
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(data, file)
}
)
}
shinyApp(ui, server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.