httd: Serve static files under a directory

Description Usage Arguments Details References Examples

View source: R/static.R

Description

If there is an ‘index.html’ under this directory, it will be displayed; otherwise the list of files is displayed, with links on their names. After we run this function, we can go to http://localhost:port to browse the web pages either created from R or read from HTML files.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
httd(dir = ".", ...)

httw(
  dir = ".",
  watch = ".",
  pattern = NULL,
  all_files = FALSE,
  handler = NULL,
  ...
)

Arguments

dir

The root directory to serve.

...

server configurations passed to server_config()

watch

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

pattern

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

all_files

whether to watch all files including the hidden files

handler

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

Details

httd() is a pure static server, and httw() is similar but watches for changes under the directory: if an HTML file is being viewed in the browser, and any files are modified under the directory, the HTML page will be automatically refreshed.

References

https://github.com/yihui/servr

Examples

1
2
3
#' see https://github.com/yihui/servr for command line usage
# or run inside an R session
if (interactive()) servr::httd()

Example output



servr documentation built on July 29, 2020, 1:06 a.m.