rstudio / revealjs

R Markdown Format for reveal.js Presentations
Other
325 stars 85 forks source link

Save and reload HTML without knitting #111

Open rleyvasal opened 3 years ago

rleyvasal commented 3 years ago

It would be great to save and automatically reload the HTML presentation without having to knit the presentation every time.

Yihui's xaringan has this option with the servr package.

Yihui described it as follows:

"You can click this addin to preview an R Markdown documents in your web browser or the RStudio Viewer, and you can enjoy LiveReload, which means as soon as you modify the document and save it, it will be automatically rebuilt and refreshed in the browser. There is no need to click the Knit button over and over again!"

cderv commented 3 years ago

You can already use the function xaringan::inf_mr() (and the associated Addin) with any R Markdown format. Did you try it with revealjs::revealjs_presentation() ?

Also, next version of RStudio (and current preview version or daily version) will have an option to "Knit on Save". This means that you will just need to Save the file modifications and the file will be re knitted without you clicking the knit button.

So current behavior:

With the new option:

xaringan::inf_mr() and its addin will do the same thing.

I don't think we have something specific to do for this revealjs package. Unless I am missing something ?

Hope it helps!

rleyvasal commented 3 years ago

I thought the new option to Save would speed up knitting process.

The new CTRL+S option in Rstudio Preview saves and knits the Rmd file - same as before (pressing knit, would knit and save the file).

Is there another difference I am not aware of? Also, is there a way to speed up the knitting process, the same way that R presentation does?

Example below shows saving the file updates the slides, no knitting needed.

presentation_save_reloads

cderv commented 3 years ago

Is there another difference I am not aware of?

No, in both case it will knit. It is just the process which is changing:

This is mainly useful with markdown only file like .md document in blogdown and with other tooling that renders .md file.

Otherwise, it is a convenient way to just to CTRL + S like any other file and not specifically Knitting to knit and save.

Also, is there a way to speed up the knitting process, the same way that R presentation does?

R Presentation is something really specific. I don't really know how it works on the backend but it will probably still renders the .Rpres file to HTML - so similar to knitting process.

I am not quite following what you are seeking though. In your initial question, you mention that it is related to xaringan feature. But xaringan will re-knit the document during a live reload. It is what xaringan::inf_mr() and you should be able to use this with revealjs_presentation() too. Is that not working ?

jjallaire commented 3 years ago

I believe that R presentation speeds up the render by using the knitr cache by default. If you enable the knitr cache for your document you'll get much faster renders.

cderv commented 3 years ago

Oh that makes sense and that would explain. Thanks!

If anyone new to knitr caching, this page is a good start: https://bookdown.org/yihui/rmarkdown-cookbook/cache.html