Reputation: 15708
I have an interactive Rmarkdown
document which embeds a few shiny apps that generates graphs based on user inputs.
After I am happy with the graphs generated, I would like to save the report (so that it becomes static).
I have opened the report in my browser (Chrome), and tried printing to pdf. It sort of works, however some figures are cut into two by the page break.
Does anyone know what is the best way to print/save such reports?
Upvotes: 2
Views: 1083
Reputation: 1327
You can give a download button on the ui.R as:
downloadButton('report', 'Download PDF'
)
And the corresponding server.R code:
library(knitr)
output$report = downloadHandler(
filename = function() {
paste("Report_", <date/identifier>, ".pdf", sep="")
},
content = function(file) {
rnw <- normalizePath('input.rnw') # assuming you wrote the code to display the graphs etc in this file
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(rnw, 'input.rnw')
out = knit2pdf(rnw, clean=TRUE)
file.rename(out, file)
}
)
Upvotes: 0
Reputation: 1089
I think it's a bit tricky but this is what i use on my app to save html plot
on pdf or png format.
wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service.
This allow you to convert a html
file into pdf
or img
.
In my ShinyApp
i use inside a downloadHandler()
function somthing like this :
system("wkhtmltopdf --enable-javascript --javascript-delay 2000 plot.html plot.pdf")
I think for your example you could simply convert your html
by using :
system("wkhtmltopdf yourFile.html yourFile.pdf")
Upvotes: 2