Debian Codegraph @

man/downloadButton.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/bootstrap.R
3 \name{downloadButton}
4 \alias{downloadButton}
5 \alias{downloadLink}
6 \title{Create a download button or link}
7 \usage{
8 downloadButton(
9 outputId,
10 label = "Download",
11 class = NULL,
12 ...,
13 icon = shiny::icon("download")
14 )
15
16 downloadLink(outputId, label = "Download", class = NULL, ...)
17 }
18 \arguments{
19 \item{outputId}{The name of the output slot that the \code{downloadHandler}
20 is assigned to.}
21
22 \item{label}{The label that should appear on the button.}
23
24 \item{class}{Additional CSS classes to apply to the tag, if any.}
25
26 \item{...}{Other arguments to pass to the container tag function.}
27
28 \item{icon}{An \code{\link[=icon]{icon()}} to appear on the button. Default is \code{icon("download")}.}
29 }
30 \description{
31 Use these functions to create a download button or link; when clicked, it
32 will initiate a browser download. The filename and contents are specified by
33 the corresponding \code{\link[=downloadHandler]{downloadHandler()}} defined in the server
34 function.
35 }
36 \examples{
37 \dontrun{
38 ui <- fluidPage(
39 p("Choose a dataset to download."),
40 selectInput("dataset", "Dataset", choices = c("mtcars", "airquality")),
41 downloadButton("downloadData", "Download")
42 )
43
44 server <- function(input, output) {
45 # The requested dataset
46 data <- reactive({
47 get(input$dataset)
48 })
49
50 output$downloadData <- downloadHandler(
51 filename = function() {
52 # Use the selected dataset as the suggested file name
53 paste0(input$dataset, ".csv")
54 },
55 content = function(file) {
56 # Write the dataset to the `file` that will be downloaded
57 write.csv(data(), file)
58 }
59 )
60 }
61
62 shinyApp(ui, server)
63 }
64
65 }
66 \seealso{
67 \code{\link[=downloadHandler]{downloadHandler()}}
68 }