Consuming R through API endpoints with Domino Data Lab

This is a follow-up to the post about deploying R models using web services.

Within 1 hour I was able to take an existing R function and publish to the Domino Data Lab web service AND write a simple Python script to call the service.   Domino make it super simple.

The R code I used was the Sales Price calculator I previously wrote about on Rpubs.

I stripped out any calling code so the R script uploaded to Domino was just a function.

Domino Project Screen

The next step was to create the API end point that calls the R function. This is as simple as pasting in the name of the R script along with the function name.

Domino End Points

With the API end point published it’s just a case of consuming it.  Domino provide sample code in lots of different languages.  I chose Python  (I’m currently learning Python).

The is a very simple example.

import unirest
import json
import yaml

business_name = "Nelsons"
rating =6
turnover = 20000
competitor_intensity = 5
months_trading = 12
product = "Maloja FadriM Multisport Jacket"
quantity = 20

response ="",
        "X-Domino-Api-Key": "Enter your private API key here",
        "Content-Type": "application/json"
        "parameters": [business_name, rating, turnover, competitor_intensity, months_trading, product, quantity]

response_data = yaml.load(response.raw_body)
print (response_data['result'])

Python Output

The beauty of this – the code can be called from anywhere.  My account with Domino has the free instance but paid instances can be spun up with huge amounts of RAM.

There are so many options around now that help with the analytical workflow.  Of course, data preparation is still time consuming but we’re seeing tools and packages to make it more efficient.

How about taking a legacy spreadsheet.  Take the processing out to R and then publish it for consumption by a web app using Shiny or Domino.

In my past I’ve created many excel apps. I always wanted a way to publish them to save me from “file/open/refresh/email”.

We have different options today.


About Lee Hawthorn

Data Professional
This entry was posted in Analytics, Deployment, R and tagged , . Bookmark the permalink.

Leave a Reply