Home Comments Thread
New Thread

One Little Thing: Embed a File in the HTML Output of R Markdown - Want to embed data or source files in HTML output? No problem! | /en/2018/07/embed-file/

yihui yihui 2022-12-17 03:56:12

One Little Thing: Embed a File in the HTML Output of R Markdown - Want to embed data or source files in HTML output? No problem!

https://yihui.org/en/2018/07/embed-file/

5 Comments

giscus-bot giscus-bot 2022-12-17 03:56:13
Guest *mielniczuk* @ 2018-09-10 16:37:40 originally posted:

Elegant enhancement that makes sharing much easier. Works fine for me on one file, but quick test on multiple files produces err:
"cannot remove file 'C:UsersOWNERAppDataLocalTempRtmpmYj1JW/tabutest.zip', reason 'No such file or directory'
Show Traceback
Error in file(what, "rb") : cannot open the connection"

source file location and name OK; anti-virus turned off
thoughts?

yihui yihui 2022-12-17 03:56:17

DId you read the help page ?xfun::embed_files and install Rtools? You can verify it via Sys.which('zip').

Originally posted on 2018-09-10 20:23:58

giscus-bot giscus-bot 2022-12-17 03:56:17
Guest *mielniczuk* @ 2018-09-11 15:19:32 originally posted:

thanks - that did it - my fault, should have RTFM

yihui yihui 2022-12-17 03:56:18

It was partially my fault. The error message was confusing. I have provided a more informative one after seeing your message: yihui/xfun@dc8eb19

Originally posted on 2018-09-11 15:47:04

giscus-bot giscus-bot 2022-12-17 03:56:14
Guest *Patrick Kopps* @ 2019-02-01 20:16:21 originally posted:

Is it a possible to pass a variable in your rmarkdown file to xfun::embed_file()?Similarly and maybe a better question: is there plans for a xfun::embed_var() or xfun::embed_df() function(s)? Thanks!

yihui yihui 2022-12-17 03:56:19

Like this?

embed_var = function(x, ...) {
  f = tempfile(fileext = '.rds')
  saveRDS(x, f)
  xfun::embed_file(f, ...)
}

Originally posted on 2019-02-02 15:48:47

giscus-bot giscus-bot 2022-12-17 03:56:15
Guest *Domenico Simone* @ 2019-08-30 05:59:35 originally posted:

Hello, it seems to me that the embed_file function is not available in the version available through conda. any plan to update it? Nice tool anyway! Thanks!

yihui yihui 2022-12-17 03:56:20

This function was added in xfun v0.4 and released to CRAN ten months ago: https://github.com/yihui/xfun/releases I don't use conda, and I don't know how to update R packages in it. In R, you just run update.packages().

Originally posted on 2019-08-30 14:38:00

giscus-bot giscus-bot 2022-12-17 03:56:16
Guest *AC* @ 2020-01-16 09:46:31 originally posted:

I found some strange behavior with embed_dir and embed_file(s). Whenever I want to add an html or xlsx file as downloadable zip in the markdown output I always receive a "network error" when trying to download it.

However, the function itself, when started in the R console performs without error. A Sys.which('zip') tells me I have it installed correctly ["/usr/bin/zip"], which is not surprising as PDF, EPS and SVG files as well as csv tables are not a problem to download as zipped files.

My OS is Ubuntu 18.04 and I therefore have no Rtools installed.

Edit:

I just checked with different browsers:

Opera: problems exist
Chrome: problems exist
Firefox: no problems
Edge/IE: not tested

yihui yihui 2022-12-17 03:56:21

I cannot reproduce this issue with either xfun::embed_files("test.html") or xfun::embed_files("test.html") and Chrome on Ubuntu 18.04. Could you file an issue to https://github.com/yihui/xfun and upload the problematic example (you can zip all files and upload in the issue)?

BTW, please make sure your issue is different with the existing one: yihui/xfun#23 Thanks!

Originally posted on 2020-01-16 20:22:56

giscus-bot giscus-bot 2022-12-17 03:56:22
Guest *AC* @ 2020-01-20 10:38:57 originally posted:

Hi!

I just checked again and the files which do not download in Chrome/Chromium are indeed larger than 2Mb. Therefore I highly suspect the "feature" from https://github.com/yihui/xfun/issues/23 to be the reason, as I do not have any problems with Firefox.

jenineharris jenineharris 2023-10-20 15:45:26

Is there any way to embed a password so that, when people click on the link to download, they are prompted for a password first? I read through the help documentation and did some searching but did not see this functionality. Thanks for such a great package!!!

yihui yihui 2023-10-20 16:05:34

Password protection is likely to be meaningless to people who understand HTML and base64 encoding, because the file is embedded in HTML as a base64 string. As long as you give them the HTML page, they will have access to this string, and they can easily decode it by themselves without clicking on the link. If you want to password protect a file, I'd recommend encrypting it before embedding it. Then people can download and decrypt it using the password you told them.

That said, it's certainly possible to prompt a password input---it just won't really protect your file, and people can easily work around it.

jenineharris jenineharris 2023-10-20 16:10:52

Ok, thank you! That makes sense.

Sign in to join the discussion

Sign in with GitHub