Serves a built site, or a mirror, on a local port with the cross-origin isolation headers webR needs. The server runs on httpuv's own thread, so it keeps answering while R is busy. Requires the httpuv package.
Usage
reading_room(
path = ".",
port = NULL,
watch = FALSE,
block = TRUE,
open_browser = rlang::is_interactive()
)Arguments
- path
A collection or any directory inside one, whose built site (
build.output-dir) is served, or any other directory holding anindex.html, such as a mirror fromcollection_mirror(), which is served as it is.- port
Port number.
NULL(the default) picks a free port. A port that is already in use is an error.- watch
If
TRUE, build the collection, serve it, and rebuild it whenever_webrarian.ymlor an included file changes. A change to the included files only updatesvfs-files/and the page's file list, and any other change runs a fullbind(). The open page reloads itself after a successful rebuild (a small script added when the page is served, never written to the site). A failed rebuild keeps the last good site and is tried again after the next change. Needsblock = TRUE, because the watch loop, which also answers the page's reload checks, runs in the console.- block
If
TRUE(the default), keep the console busy until you press Ctrl+C, then stop the server. IfFALSE, return at once, and the server keeps running untilreading_room_close()or the room'sclose().- open_browser
If
TRUE, open the preview in the default browser. Defaults toTRUEin interactive sessions only.
Value
Invisibly, the reading room. Its url and port elements give the
address, and its close() element stops it. Previewing the same site again
stops the earlier preview and says so.
Examples
if (interactive() && requireNamespace("httpuv", quietly = TRUE)) {
collection <- file.path(tempdir(), "webrarian-preview-demo")
catalog(collection)
bind(collection)
# Serve in the background and keep the console free
room <- reading_room(collection, block = FALSE)
room$url
room$close()
# Rebuild on every change, and reload the page, until you press Ctrl+C
reading_room(collection, watch = TRUE)
}