flexdashboard icon indicating copy to clipboard operation
flexdashboard copied to clipboard

Print options preclude the use of pagedown

Open eamcvey opened this issue 3 years ago • 3 comments

It would be quite useful to be able to print a flexdashboard to pdf as a backup method to provide the content to people.

Per this issue, https://github.com/rstudio/pagedown/issues/229, this doesn't work currently with pagedown/Chrome print and flexdashboards due to the print CSS rules in bootstrap:

@media print { *, *:before, *:after { background: transparent !important; color: #000 !important; -webkit-box-shadow: none !important; box-shadow: none !important; text-shadow: none !important; } }

Perhaps these are important for other reasons, but if there were at least an easy option in flexdashboard to override them, it would be lovely. I have evidence that I'm not the only one who would be interested in this capability.

eamcvey avatar Jun 24 '21 13:06 eamcvey

Bootstrap's print rules aren't the (main) issue here. There's at least two other issues at play:

  1. vertical_layout: fill doesn't work in the way it probably should in print because these rules probably need to also be applied for print

https://github.com/rstudio/flexdashboard/blob/master/inst/www/flex_dashboard/fillpage.css

  1. A larger, more troubling, issue is that it appears Chrome's print utility is unable to properly render a base64 encoded background on a <p> tag, but this is how flexdashboard renders static images. For a minimal reprex, note that this image renders in Chrome fine, but it doesn't for print:
library(htmltools)

uri <- base64enc::dataURI(file = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/R_logo.svg/2560px-R_logo.svg.png")
browsable(tags$body(
  style = "height:100%; width:100%",
  tags$p(
    style = sprintf("background: url('%s') center center / contain no-repeat;", uri),
    style = "position:absolute; top:0; left:0; right:0; bottom:0; margin: 0;"
  )
))

cpsievert avatar Jul 08 '21 17:07 cpsievert

A larger, more troubling, issue is that it appears Chrome's print utility is unable to properly render a base64 encoded background on a <p> tag

More precisely, Chrome is able to render a base64 background image but this option is disabled by default. In the Chrome print dialog box, one has to check the option "Background graphics". The pagedown::chrome_print() function modifies Chrome's default behavior and prints background by default (see here)

RLesur avatar Jul 18 '21 15:07 RLesur

If we added print styles to flexdashboard, would it be better to faithfully reproduce one state of the dashboard? Or would we try to switch to a "show everything" approach where we attempt to ensure all pages and tabs are visible and flow in the page? (I'd advocate for the second option.)

gadenbuie avatar Mar 01 '23 14:03 gadenbuie