I am attempting to add a simple download button to an Rmarkdown report but it seems like the button downloads the entire report and not the table of interest. For example, in my RMarkdown I have:
The handler generates a button but the button does not download the mtcars data, it downloads the entire html report. I'm running rmarkdown::render to generate the report.
Any assistance on adding download buttons to RMarkdown reports would be greatly appreciated.
Ah, right - using shiny functions, you can't generate a standalone html output. I found a solution using xfun::embed_file, it's not as elegant but it works.
I find it elegant ! That is a perfect solution to include a file in a static file. If you want a button rather than a link, you can try this
And
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:
Oh - awesome. The downloadthis package looks to solve this issue completely. I implemented some custom CSS to change the xfun::embed_file link into a button but it requires the extra step of saving out a file first to pass into the function. downloadthis looks like it works directly with data frames in R by wrapping the saving/button creation into one step, which is perfect.