Skip to contents

Opens a live preview of the files in a directory. The live preview server automatically renders R Markdown files when they are saved, and the preview is refreshed whenever R Markdown files or supporting files, such as .js, .css, .htm, .html, .sass, or .scss files, are updated. This functionality requires the servr package.


  path = getwd(),
  update_pattern = "[.](js|css|[Rr]?[Mm][Dd]|html?|s[ca]ss)$",
  render_quietly = getOption("js4shiny.live_preview.quiet", TRUE),
  external = FALSE

live_preview_stop(which = NULL)



The path for the directory or file to preview. If the path given is an R Markdown document or HTML document, the HTML version of that file will be opened directly, otherwise the directory containing the file will be served.


Update the live preview when files matching this pattern are updated. By default, updating files with the following extensions will update the preview: .Rmd (case insensitive), .html, .htm, .js, .css, .sass, .scss.


Arguments passed on to servr::httw


The root directory to serve.


a directory under which httw() is to watch for changes; if it is a relative path, it is relative to the dir argument


a regular expression passed to list.files() to determine the files to watch


whether to watch all files including the hidden files


a function to be called every time any files are changed or added under the directory; its argument is a character vector of the filenames of the files modified or added


If TRUE (default), the output from rmarkdown::render() will not be shown. Set to FALSE for debugging. You can set the default value with a global option:

options(js4shiny.live_preview.quiet = FALSE)


Should the live preview be opened in an external browser? The default is FALSE and the preivew is opened in the RStudio viewer pane (if launched inside RStudio).


A integer vector of the server IDs; by default, IDs of all existing servers in the current R session obtained from daemon_list(), i.e., all daemon servers will be stopped by default.


Invisibly returns the servr::httw() object, so that you can manually stop the server with the $stop_server() method.


  • live_preview_stop: Stop the live preview background daemons. See servr::daemon_list() for more information.

RStudio Addins

There are three Live Preview addins provided by js4shiny. Live Preview and Live Preview (External) open a live preview of the directory of the currently open document, if possible at the current HTML document corresponding to the open document. The external preview addin automatically opens the preview in your web browser, otherwise the preview is opened in the RStudio Viewer pane.

To stop the live server, you can call servr::daemon_stop() or live_preview_stop(), which will stop all bakground servr daemons, or you can use the Live Preview Stop addin.


if (interactive()) {

tmp_dir <- tempfile("live-preview")
tmp_rmd <- file.path(tmp_dir, "js4shiny-plain.Rmd")

# Create a new js4shiny plain HTML document. If interactive
# and in RStudio, this file will open and you can use the
# addins to launch the live preview
js4shiny_rmd("js", full_template = TRUE, path = tmp_rmd)

srvr <- live_preview(tmp_rmd)

# Stop all background servers with either of the following
# live_preview_stop()
# servr::daemon_stop()
# Or if you've saved the return value from live_preview()
# srvr$stop_server()