R built in Web server

Take a look at Rook - it's on GitHub. About setting a port number, see ?tools::help.ports it accepts a vector of numbers (integers) and it will choose the first available one. There's also sinartra (CRAN, GitHub), but I'd rather go with Rook.


It looks like servr might be what you're looking for these days.

From github:

To some degree, this package is like python -m SimpleHTTPServer or python -m http.server.

https://github.com/yihui/servr

https://cran.rstudio.com/web/packages/servr/index.html

Example code

writeLines("<h1>Hi</H1>", "index.html")

# install.packages("servr")
library(servr)
servr::httd()

# createTcpServer: address already in use
# To stop the server, run servr::daemon_stop(2) or restart your R session
# Serving the directory /Users/st/R/localhost at http://127.0.0.1:7826

Place the address in the browser: http://127.0.0.1:7826

Tags:

R