Skip to content Skip to sidebar Skip to footer

How To Render Dt::datatables In A Pdf Using Rmarkdown?

How can I display DT::datatable objects from a rmarkdown script onto a pdf document? My code so far is breaks down with the following error: processing file: reportCopy.Rmd output

Solution 1:

Since knitr v1.13, HTML widgets will be rendered automatically as screenshots taken via the webshot package.

You need to install the webshot package and PhantomJS:

install.packages("webshot")
webshot::install_phantomjs()

(see https://bookdown.org/yihui/bookdown/html-widgets.html)

Solution 2:

You cannot usedatatable in pdf_document (datatable is interactive, pdf is static), only in html_document! The only possibility for PDF is to use the kable or for example pandoc.table

--> if You really wanna get the look of datatable and as You said datatable is created in a shiny application, then You can have a look at the webshot package, which is going to create a screenshot of Your datatable from shiny app which You can use further in pdf as a image.

Post a Comment for "How To Render Dt::datatables In A Pdf Using Rmarkdown?"