For a file, first encode it into base64 data (a character string). Then
generate a hyperlink of the form <a href="base64 data"
download="filename">Download filename</a>. The file can be downloaded when
the link is clicked in modern web browsers. For a directory, it will be
compressed as a zip archive first, and the zip file is passed to
embed_file(). For multiple files, they are also compressed to a zip
1 2 3 4 5
Path to the file(s) or directory.
The default filename to use when downloading the file. Note that
The text for the hyperlink.
These functions can be called in R code chunks in R Markdown documents with HTML output formats. You may embed an arbitrary file or directory in the HTML output file, so that readers of the HTML page can download it from the browser. A common use case is to embed data files for readers to download.
An HTML tag <a> with the appropriate attributes.
Windows users may need to install Rtools to obtain the
command to use
These functions require R packages mime, base64enc, and htmltools. If you have installed the rmarkdown package, these packages should be available, otherwise you need to install them separately.
Currently Internet Explorer does not support downloading embedded files (https://caniuse.com/#feat=download).
1 2 3 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.