3

Furthermore, can you loop the print out based on a specific variable?

Say for example I have one view for a vendor. How can I print out a PDF view iteratively based on this vendor? Basically, it would be a unique view for each vendor

Jaskeil
  • 1,044
  • 12
  • 33
  • 1
    Relevant, but maybe not the current state of the art: https://rviews.rstudio.com/2017/06/28/printing-from-flex-dashboard/ – Jon Spring May 11 '21 at 18:33
  • Flexdashboard is designed for interactive exploration. I'd rather use an external markdown for PDF publishing (they can share code thru the use of common functions in an external .R file) – HubertL May 11 '21 at 19:50
  • 1
    As mentioned by HubertL, flexdashboard is by design a html page that can embed interactive elements. You can print to pdf via a browser or knit to pdf. Nonetheless, I would create a non-flexdashboard Rmd for static output. To create "unique" views for a vendor, read up on parameterised reports. Supplying a parameter for a vendor (= params$vendor) you can filter your data, etc. to populate the Rmd output. You can create a render script that basically loads the Rmd and passes the (set of) parameter(s) to create your designed output: https://bookdown.org/yihui/rmarkdown/parameterized-reports.html – Ray May 11 '21 at 20:25
  • Thank you so much, this is very helpful. The issue I have with RMarkdown is that I haven't found much documentation on created a landscape file with plots/views shown on different "boxes" of a given page, please correct me if I am wrong however – Jaskeil May 12 '21 at 12:21

1 Answers1

0

I wanted to do the same thing! I understand people saying it's not what it's intended for but sometimes you just need to use a workaround! Your options are...

#make a PNG
webshot::webshot("your_flexdashboard.html", "your_new_file.png")

#convert PNG to PDF
magick::image_write(
  image = magick::image_read("your_new_file.png"), 
  format = "pdf", 
  path =  "your_new_file.pdf"
)

Or... (works best if one page)

psycModel::html_to_pdf("your_flexdashboard.html")

Let me know if more explanation is needed. The first option works for plotly hthml widgets but for me didn't work for DT tables.

To loop this simply use a for loop and list of your dashboards.

FILES<-list.files("flexfolder")

for (FILE in FILES){
psycModel::html_to_pdf(FILE)
}
  • I couldn't try your first way but the second one does not create pdf with the flexdashboard colors. – pRo Feb 28 '23 at 08:42