How to create a link that downloads a new file instead of opening the source file


#1

My rmarkdown code produces a html document. This document lists out the process that needs to be followed by front line staff at month end. The process flow requires users to open xl files, update a few fields (such as rport month etc) and then run macros.

I have used hyperlink to the original XL files as follows
[click to opel xl file](path/and/file names)

  • The above link opens the original file and the user is able to overwrite the original file, I don’t want this to happen.
  • I want the hyperlink to generate a new file that would be downloaded so that nothing happens to the original file.

How to do this?

Please could you kindly help me out.

Thanks in advance.

Kind regards,
Joe


#2

I don’t think a static link in RMarkdown can do, I think you’re in Shiny interactive document territory (if that’s not already what you’re doing). If you are using Shiny (or switch over to using it), I’d recommend you move this post over to the Shiny category (you can still tag it as R Markdown, I think you’ll get better help that way, though— you just change the category in the dropdown if you go to edit the post, see pic below).

You might want to look at @barbara’s output args and render functions tutorial (though it doesn’t specifically cover xl— I’m not sure what the best method is for actually writing directly to that file extension, I know you can write_excel_csv() with readr).


#3

Similar to @mara’s recommendation, but in a slightly different direction, you could probably use parameterized reports


#4

Yeah, there’s a nice Generating downloadable reports tutorial by @winston right after the output args one (right below it in the navigation), so we’re on the same page! :+1: