% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/download_button.R
\name{download_button}
\alias{download_button}
\title{Download button}
\usage{
download_button(outputId, button_label, file_type = "CSV", file_size = NULL)
}
\arguments{
\item{outputId}{The name of the output slot that the
\code{shiny::downloadHandler()} is assigned to}

\item{button_label}{Text that will appear describing the download action.
Vague text like 'click here' or 'here' will cause an error, as will ending
in a full stop. Leading and trailing white space will be automatically
trimmed. If the string is shorter than 7 characters a console warning will
be thrown. There is no way to hush this other than providing more detail}

\item{file_type}{The file type to be download (default: CSV)}

\item{file_size}{The file size if known. Needs to be a string ending in one
of KB, MB, GB or rows}
}
\value{
shiny tag object
}
\description{
The \code{download_button()} provides a standard way to provide a download
link, which facilitates important accessible / positive user experience
elements, namely:
\itemize{
\item file type
\item file size
}
These are necessary in order for users to understand what they are
downloading, both in terms of being able to decide if they are comfortable
with downloading the file over their current connection and if it's in a
form they're able to deal with once it is downloaded. If the exact file
size is not easily determined, then it may be acceptable to provide an
estimate or an upper limit.
}
\examples{
ui <- shiny::fluidPage(
  gov_text("Choose a data set to download."),
  select_Input(
    "dataset",
    "Data set",
    select_text = c("Car road tests", "New York air quality"),
    select_value = c("mtcars", "airquality")
  ),
  download_button(
    "download_data",
    "Download selected data set",
    file_size = "4 KB"
  )
)

server <- function(input, output) {
  # The requested data set
  data <- reactive({
    get(input$dataset)
  })

  output$download_data <- 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)
    }
  )
}

if (interactive()) shiny::shinyApp(ui, server)
}
\seealso{
Other Govstyle actions: 
\code{\link{download_link}()},
\code{\link{download_radios}()},
\code{\link{download_radios_handler}()},
\code{\link{external_link}()}
}
\concept{Govstyle actions}
