🌏 Creating a simple web service in R


I keep getting amazed by the amount of things you can do in R. I mainly use it for plotting using ggplot package and quick analysis (thanks tidyverse), but there are other cool things such as R Markdown, Flex Dashboards, Deep Learning in R (although I prefer Python or Julia) and converting your R scripts into a web service.

Yes, but wait. Why would you want to write a service in R ? Well, one reason could be that the problem you’re trying to solve can be easily solved using an existing R package. Or it could well be that you have some script already available in R and you just want to apify it.

https://www.rplumber.io/

Assume you have defined the business login in api.r

# api.r

#* Greet the person
#* @param name Your name
#* @post /greet
function(name) {
  paste0("Welcome ", name)
}

Start the web service

# start.r

install.packages("plumber")
library(plumber)

r <- plumb("/app/api.R")
r$run(port=8998)
```

See also