#' Embed a file to HTML throght a tag
#'
#' @return
#' @export
#'
embed_file_a <- function(file,
name = basename(file),
text = paste("Download", name),
...) {
# Source: https://github.com/yihui/xfun/blob/master/R/markdown.R
# xfun::embed_file('ddrIntroduction.Rmd')
# xfun::pkg_load2(c("base64enc", "htmltools", "mime"))
message('star... paste0')
h <- paste0(
"data:",
mime::guess_type(file),
";base64,",
base64enc::base64encode(file)
)
htmltools::a(
id = "embed-rmd-file",
href = h,
download = name,
hidden = NA,
text,
...
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.