Turns a file into a download link that carries the file with it: the
contents travel base64-encoded inside the href, so the resulting
HTML needs no server and no accompanying assets. The counterpart of
as.img() for non-image files – a data set next to a table,
a script next to its output.
Details
Browsers limit the size of a data URI, so this suits spreadsheets and text files rather than large binaries.
See also
Other html:
as.html(),
as.img(),
embedFile(),
escapeHtml(),
htmlNotation,
htmlSubscript,
toHtmlTable()
Examples
fn <- tempfile(fileext = ".csv")
write.csv(head(iris), fn, row.names = FALSE)
as.fileLink(fn, label = "iris")
#> <a href="data:text/csv;base64,IlNlcGFsLkxlbmd0aCIsIlNlcGFsLldpZHRoIiwiUGV0YWwuTGVuZ3RoIiwiUGV0YWwuV2lkdGgiLCJTcGVjaWVzIgo1LjEsMy41LDEuNCwwLjIsInNldG9zYSIKNC45LDMsMS40LDAuMiwic2V0b3NhIgo0LjcsMy4yLDEuMywwLjIsInNldG9zYSIKNC42LDMuMSwxLjUsMC4yLCJzZXRvc2EiCjUsMy42LDEuNCwwLjIsInNldG9zYSIKNS40LDMuOSwxLjcsMC40LCJzZXRvc2EiCg==" download="file19772bd0c373.csv">iris</a>
unlink(fn)
