rstudio/revealjs

Save and reload HTML without knitting

rleyvasal opened this issue · 5 comments

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

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:

  • Knit the file once using the button. A new browser window open at the end with the slides
  • Use CTRL+SHIFT+K to reknit (Rmd file will be saved and slides updated).

With the new option:

  • Knit the file once using the button. A new browser window open at the end with the slides
  • Use CTRL+S to save the file, this will trigger the knit and update the slides

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!

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

Is there another difference I am not aware of?

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

  • Ask to knit the file
  • Ask to save the file

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 ?

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

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