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 given directory.

Build Status CRAN downloads from the RStudio mirror

A simple HTTP server to serve files under a given directory based on the httpuv package.

You can install this package from CRAN (stable version) or XRAN (development version):

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 python -m http.server. It may be used to serve:

You can either run servr::httd() in an interactive R session, or run from command line:

# 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

Similar to 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

Besides httd(), there are functions jekyll(), rmdv1(), and rmdv2() in this package to serve HTML files generated from R Markdown documents (via knitr or 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.

Jekyll with servr and knitr

Serve package vignettes

The function 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.

Daemonized server

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 information.




  • Added a verbose argument to server_config().

  • The interval argument of server_config() can be set via the global option servr.interval now. For example, options(servr.interval = 0.5).


  • Server functions such as httd() now return the config object created by server_config() instead of the server handle returned by httpuv::startServer(). The config object contains various information about the server and methods to start/stop the server.

       CHANGES IN servr VERSION 0.12


  • Exported the function random_port() to return an available random TCP port.


  • daemon_list() returns server IDs instead of handles, so that it will work with httpuv >= v1.4.5.1 (rstudio/blogdown#365).

       CHANGES IN servr VERSION 0.11


  • The default value of the port argument of server_config() can be set via the environment variable R_SERVR_PORT. If the environment variable does not exist, the global option servr.port will be used if set, e.g., options(servr.port = 4322). See ?servr::server_config for details.

       CHANGES IN servr VERSION 0.10


  • Added a function browse_last() to reopen the last browsed page.


  • The daemon argument in server_config() now defaults to interactive(), i.e., servr starts a daemonized server that does not block your interactive R session by default.

       CHANGES IN servr VERSION 0.9


  • The web browser may be opened too early (before the server is ready) (originally reported at rstudio/rstudio#2475).

       CHANGES IN servr VERSION 0.8


  • added another implementation of the daemoinzed server based on the later package, since the previous implmentation based on httpuv::startDaemonizedServer() could crash the R session on Windows

       CHANGES IN servr VERSION 0.7


  • added a new argument watch to servr::httw()

  • exported the function server_config()


  • files/directories that contain multibyte characters in path names cannot be served correctly (thanks, Hao Peng)

       CHANGES IN servr VERSION 0.6


  • on 404 (page not found), 404.html will be displayed if it exists under the root directory

  • improved the support for HTTP Range requests, e.g. servr can correctly serve MP4 videos now in major browsers including Safari


  • servr should decode requested paths before reading them (https://github.com/rstudio/blogdown/issues/85)

       CHANGES IN servr VERSION 0.5


  • added an argument initpath to server_config() so you can open a specific path initially in the web browser

  • the daemon argument of server_config() takes the default value from the global option getOption('servr.daemon') now, e.g., you can set options(servr.daemon = TRUE) so that the daemonized server is always used

       CHANGES IN servr VERSION 0.4.1



  • fixed a bug in 301 redirection when serving a directory without the trailing slash

       CHANGES IN servr VERSION 0.4


  • you can disable websocket listening on an HTML page using a special HTML comment <!-- DISABLE-SERVR-WEBSOCKET --> when servr is serving and watching a directory, so that this page will not communicate with R (e.g. when it is updated, R will not send signals to refresh it) (thanks @hafen, #25)

  • a random TCP port will be used if the port 4321 is not available

       CHANGES IN servr VERSION 0.3


  • added a function httw() to watch for changes under a directory and refresh an HTML page automatically (if it is being viewed in the browser) when any files are modified

  • servr accepts HTTP Range requests now (thanks, @rekado, #21)


  • servr did not work with RStudio Server (#20)

       CHANGES IN servr VERSION 0.2


  • when running inside RStudio, the RStudio web browser will be used if available (requires RStudio >= 0.98.439)

  • added three server functions jekyll(), rmdv1(), and rmdv2() to serve Jekyll websites, R Markdown v1, and R Markdown v2 documents, respectively

  • added a server function vign() to serve R Markdown/HTML package vignettes

  • added a server function make() to serve a directory and update files automatically via Makefile (#2)

  • the URL pathname foo will be redirected to foo/ automatically if foo is a directory (#5)

  • in case of errors when serving dynamic documents, the server functions will double the delay to check for updates and wait for the next build until the error is cleared (like Gmail)

       CHANGES IN servr VERSION 0.1


  • the main function httd() to start an HTTP server for a local directory

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.23 by Yihui Xie, 2 months ago


Report a bug at https://github.com/yihui/servr/issues

Browse source code at https://github.com/cran/servr

Authors: Yihui Xie [aut, cre] , Carson Sievert [ctb] , Jesse Anderson [ctb] , Ramnath Vaidyanathan [ctb]

Documentation:   PDF Manual  

Task views: Web Technologies and Services

GPL license

Imports mime, httpuv, xfun, jsonlite

Suggests tools, later, rstudioapi, knitr, rmarkdown

Imported by azuremlsdk, blogdown, iheiddown, mapview, pagedown, papayar, redist, rgexf, xaringan.

Suggested by LDAvis, animint2, bookdown, brainR, dataspice, webdriver.

See at CRAN