yihui / printr

Some (magical) printing methods for knitr
https://yihui.org/printr/
118 stars 24 forks source link

support for DT #33

Open cboettig opened 6 years ago

cboettig commented 6 years ago

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/

yihui commented 6 years ago

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)
}
cboettig commented 6 years ago

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?

yihui commented 6 years ago

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 commented 6 years ago

This should work:

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