A Simple HTTP Server to Serve Static Files or Dynamic Documents
Start an HTTP server in R to serve static files, or dynamic
documents that can be converted to HTML files (e.g., R Markdown) under a
A simple HTTP server to serve files under a given directory based on the httpuv package.
install.packages('servr') # stable version; use a CRAN mirror, or install.packages('servr', repos = 'https://xran.yihui.name') # devel version
This package is licensed under GPL.
Serve static files
To some degree, this package is like
python -m SimpleHTTPServer or
http.server. It may be used to serve:
- R Markdown applications
- googleVis charts (to solve the Flash security problem)
- D3 charts which need to load JSON from local files (see also the animint package)
- rCharts and samatha, etc
You can either run
servr::httd() in an interactive R session, or run from
# default: port 4321, do not launch browser Rscript -e 'servr::httd()' # open a web browser Rscript -e 'servr::httd()' -b # listen on port 4000 Rscript -e 'servr::httd()' -p4000 # pass arguments to the httd() function Rscript -e 'servr::httd(,4000,TRUE)'
There is also a shell script under
system.file('bin', package = 'servr');
if it is added to
PATH, you can simply run
servr # serve the current directory servr -b # launch the browser servr -b -p4000 # change port to 4000
Serve and watch a directory
httd(), the function
httw() can both serve and watch a directory.
If you are viewing an HTML file in the browser, it will be automatically
refreshed whenever there are any changes in the directory (e.g. you added,
deleted, or modified certain files in the directory).
Serve dynamic documents
httd(), there are functions
this package to serve HTML files generated from R Markdown documents (via
rmarkdown). R Markdown documents can be
automatically re-compiled when their HTML output files are older than the
corresponding source files, and HTML pages in the web browser can be
automatically refreshed accordingly, so you can focus on writing R Markdown
documents, and results will be updated on the fly in the web browser. This is
even more useful when you write R Markdown documents in the RStudio IDE, because
the HTML files are displayed in the RStudio viewer pane, and you can put the
source document and its output side by side.
Serve package vignettes
vign() can be used to serve R Markdown/HTML package vignettes.
The HTML output files are generated and displayed in the web browser so you can
preview the vignettes, and they will be cleaned up after they are loaded in the
web browser to make sure your source package is clean.
All server functions can be used in the daemonized mode, i.e., they can be
non-blocking in the R session, which allows you to continue working in the R
console after the server is launched. This mode can be set via the argument
daemon = TRUE in most server functions. See
?server_config for more
Functions in servr
|jekyll||Serve R Markdown based websites|
|httd||Serve static files under a directory|
|vign||Serve R Markdown/HTML package vignettes|
|daemon_stop||Utilities for daemonized servers|
|browse_last||Reopen the last browsed page|
|make||Serve files under a directory based on GNU Make|
|notebook||Serve R notebooks|
|serve_example||A convenience function to serve examples in this package|
Last month downloads
|Packaged||2018-10-23 16:39:35 UTC; yihui|
|Date/Publication||2018-10-23 17:00:02 UTC|
Include our badge in your README