With the help of this wonderful community, I've managed to learn a bit more about how to deploy a model developed in R as a web API.
As far as I could discover so far, the easiest way to achieve this would be using R Studio Connect and Plumber as described in this great video here.
However, R Studio Connect pricing begins at $25.000/year and I can't afford it, since this is a small POC project and it will have only a few API calls a day.
So, my host has installed R in my Linux server per my request, and I can see it is there by calling it from the terminal:
So this is my bottleneck right now.
Where to go from here? Should I upload the R script to a folder in the server? Which one, and how to call that script? And how to install Plumber and other R packages?
I'm sure there's still a long way to go and a lot to read during this lockdown, so I'd appreciate some guidance.
You can install the packages from that terminal you have opened, using for example: install.packages('plumber')
Then, you should upload your script and all its dependencies (.RDS, .CSV, etc).
Supposing that your script is called plumber.R, you can create an other script myapi.R that contains the following configuration (to make the api available over the internet, on port 8000 for example):
r <- plumber::plumb("plumber.R")
r$run(host="0.0.0.0", port=8000)
and then you can call this script from the linux terminal using Rscript command using: Rscript myapi.R
you might also add cronjobs or other scripts to automatically start this scrip when it crashes.
Good luck.
Hi, it seems that the package was not successfully installed.
also, you need to run the command Rscript myapi.R from the shell terminal and not from R terminal.
I mean, the same way you opened "R", but instead of typing R, you type: ls to show files, and make sure "myapi.R" is in the same directory, then you type: Rscript myapi.R
if it's not in the same directory , you can provide its path, like: Rscript ~/home/user/my_scripts/myapi.R.
For me on my server, if I run it from Rstudio, the API url has some characters before the /echo
can you try adding them manually, so it become something like: https://... azureml.ms/p/ffee3d60/echo?msg=hello
(the ones that appear in the url of the documentation link, next to "open in browser" button)
Otherwise, can you run it and then open the link in the browser specifying the port number after the hostname, like: https:// ...... azureml.ms:8000/echo?msg=hello