printr icon indicating copy to clipboard operation
printr copied to clipboard

support for DT

Open cboettig opened this issue 8 years ago • 4 comments

It would be great to have printr's magic work with the elegant jquery tables from the DT package for HTML documents...

http://rstudio.github.io/DT/

cboettig avatar Dec 11 '17 21:12 cboettig

If you want to turn data frames to DataTables, you can customize the knit_print method, e.g.

library(knitr)
knit_print.data.frame = function(x, ...) {
  DT::datatable(x)
}

yihui avatar Dec 12 '17 16:12 yihui

Thanks! Is customizing the knit_print methods now the preferred way of setting these than doing library(printr)?

Also, for some reason, I am not getting this to work in blogdown sites, though it works fine if I compile that page alone (e.g. with rmarkdown::render()). Any hints or should I open a blogdown issue with MRE when I get a chance?

cboettig avatar Dec 13 '17 20:12 cboettig

No, printr is essentially a collection of knit_print methods. I just meant that you could override these methods.

I don't know why it doesn't work with blogdown, but I can reproduce your issue, so I don't need a MRE. Thanks!

yihui avatar Dec 18 '17 06:12 yihui

This should work:

knit_print.data.frame = function(x, ...) {
  knit_print(DT::datatable(x), ...)
}

yihui avatar Dec 23 '17 04:12 yihui