Use these functions to create a download button or link; when clicked, it
will initiate a browser download. The filename and contents are specified by
the corresponding downloadHandler() defined in the server
function.
downloadButton(
outputId,
label = "Download",
class = NULL,
...,
icon = shiny::icon("download"),
enabled = "auto"
)
downloadLink(outputId, label = "Download", class = NULL, ..., enabled = "auto")The name of the output slot that the downloadHandler
is assigned to.
The label that should appear on the button.
Additional CSS classes to apply to the tag, if any.
Other arguments to pass to the container tag function.
An icon() to appear on the button. Default is icon("download").
Controls the enabled/disabled behavior of the button or link.
Defaults to "auto".
"auto": the button or link starts disabled and is automatically
enabled once the server has initialized the downloadHandler.
TRUE: the button or link starts enabled immediately, without waiting
for the downloadHandler.
FALSE: the button or link starts disabled and Shiny will never
automatically enable it, even after the downloadHandler is ready.
You are responsible for managing the enabled/disabled state yourself
(e.g., with shinyjs::enable() and shinyjs::disable()).
if (FALSE) { # \dontrun{
ui <- fluidPage(
p("Choose a dataset to download."),
selectInput("dataset", "Dataset", choices = c("mtcars", "airquality")),
downloadButton("downloadData", "Download")
)
server <- function(input, output) {
# The requested dataset
data <- reactive({
get(input$dataset)
})
output$downloadData <- downloadHandler(
filename = function() {
# Use the selected dataset as the suggested file name
paste0(input$dataset, ".csv")
},
content = function(file) {
# Write the dataset to the `file` that will be downloaded
write.csv(data(), file)
}
)
}
shinyApp(ui, server)
} # }