yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.39k stars 878 forks source link

Extending knitr chunk options #1300

Closed schloerke closed 8 years ago

schloerke commented 8 years ago

@hafen and I have a goal to lazy-load html widgets when producing a html_document with rmarkdown.

We have successfully done that here: https://github.com/hafen/lazyrmd/blob/master/R/knit_print.R . This is accomplished with the chunk parameter lazy = TRUE and producing a htmlwidget object in that chunk. (The htmlwidget is then produced in a stand alone page. This dramatically reduces the initial load time (30+ seconds to a couple seconds) for the website when there are multiple (10+) htmlwidgets.)

I am wondering where I should submit a PR to have this option adopted/extended. If knitr has a method to extend chunk options, I'd be happy to make sure htmlwidgets does this. If not, I'd be happy to submit this to knitr as a new chunk option.

Thank you for your time!

Best, Barret

yihui commented 8 years ago

I can see this is certainly useful. knitr's chunk options are very much open-ended; you can create any options and define your own printing behavior, which is what you have done in lazyrmd. I guess the only thing that you may frown upon is your knit_print.htmlwidget "overrode" htmlwidgets' knit_print.htmlwidget. That is fine to me. If you don't like it, you can define your own printing function, say, lazy_print, and use the chunk option render = lazyrmd::lazy_print, and in this lazy_print function, you decide what to do based on options$lazy. Anyway, I guess there isn't much I need to do on my side: lazyrmd seems to be a useful and handy little package.

schloerke commented 8 years ago

Thank you for the comments! I'll check with Ryan to see where we want to take the package from here.

github-actions[bot] commented 4 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.