serve_book: Continuously preview the HTML output of a book using the...

Description Usage Arguments Details

View source: R/utils.R


When any files are modified or added to the book directory, the book will be automatically recompiled, and the current HTML page in the browser will be refreshed. This function is based on servr::httw() to continuously watch a directory.


  dir = ".",
  output_dir = "_book",
  preview = TRUE,
  in_session = TRUE,
  quiet = FALSE,



The root directory of the book (containing the Rmd source files).


The directory for output files; see render_book().


Whether to render the modified/added chapters only, or the whole book; see render_book().


Whether to compile the book using the current R session, or always open a new R session to compile the book whenever changes occur in the book directory.


Whether to suppress output (e.g., the knitting progress) in the console.


Other arguments passed to servr::httw() (not including the handler argument, which has been set internally).


For in_session = TRUE, you will have access to all objects created in the book in the current R session: if you use a daemonized server (via the argument daemon = TRUE), you can check the objects at any time when the current R session is not busy; otherwise you will have to stop the server before you can check the objects. This can be useful when you need to interactively explore the R objects in the book. The downside of in_session = TRUE is that the output may be different with the book compiled from a fresh R session, because the state of the current R session may not be clean.

For in_session = FALSE, you do not have access to objects in the book from the current R session, but the output is more likely to be reproducible since everything is created from new R sessions. Since this function is only for previewing purposes, the cleanness of the R session may not be a big concern. You may choose in_session = TRUE or FALSE depending on your specific applications. Eventually, you should run render_book() from a fresh R session to generate a reliable copy of the book output.

bookdown documentation built on Sept. 5, 2021, 5:19 p.m.