httd function

Serve static files under a directory

Serve static files under a directory

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.

httd(dir = ".", ..., response = NULL) httr(dir = ".", ...) httw( dir = ".", watch = ".", pattern = NULL, all_files = FALSE, filter = NULL, handler = NULL, ... )

Arguments

  • dir: The root directory to serve.
  • ...: Server configurations passed to server_config().
  • response: A function of the form function(path, res, ...) that takes a file path and server response as input, and return a new response. This can be useful for post-processing the response (for experts only).
  • 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.
  • filter: A function to filter the file paths returned from list.files() (e.g., you can exclude certain files from the watch list).
  • 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 static file server by default (its response

argument can turn it into a dynamic file server).

httr() is based on httd() with a custom response function that executes R files via xfun::record(), so that you will see the output of an R script as an HTML page. The page will be automatically updated when the R script is modified and saved.

httw() is similar to httd() 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.

Examples

servr::httd()

References

https://github.com/yihui/servr

  • Maintainer: Yihui Xie
  • License: GPL
  • Last published: 2024-10-04