Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Easing the Path to Production - APIs in R

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for sellorm sellorm
October 08, 2016

Easing the Path to Production - APIs in R

Writing API's in R is a fast and efficient way to embed powerful analytic capabilities within your organisation

Avatar for sellorm

sellorm

October 08, 2016

More Decks by sellorm

Other Decks in Programming

Transcript

  1. Mark Sellors – Head of Data Engineering [email protected] Easing the

    Path to Production Building API’s in R Mark Sellors – Mango Solutions
  2. Mark Sellors – Head of Data Engineering [email protected] Me •

    Head of Data Engineering • Devops/DataOps • Data Architecture • API’s • Analytic Maturity • Automation • Industrialisation
  3. Mark Sellors – Head of Data Engineering [email protected] Mango Solutions

    • R Specialists • Data Science Consulting • Data Science Training • Software Development Web: www.mango-solutions.com Twitter: @MangoTheCat
  4. Mark Sellors – Head of Data Engineering [email protected] Agenda •

    API’s • Introducing plumber • How it works • Examples • Caveats • A simple case study • Summary
  5. Mark Sellors – Head of Data Engineering [email protected] Example -

    simple function > adder <- function(a, b){ + a + b + } > adder(4, 3) [1] 7
  6. Mark Sellors – Head of Data Engineering [email protected] Example -

    add plumber #* @get /adder > adder <- function(a, b){ + as.numeric(a) + as.numeric(b) + }
  7. Mark Sellors – Head of Data Engineering [email protected] Example -

    running with plumber > library(plumber) > r <- plumb("my_api_file.R") > r$run(port=8000)
  8. Mark Sellors – Head of Data Engineering [email protected] Example -

    Accessing the API # curl http://localhost:8000/adder?a=4&b=3
  9. Mark Sellors – Head of Data Engineering [email protected] Moving beyond

    the shiny app • split the application up • turn the function into a general purpose service • refactor the shiny app to use the API
  10. Mark Sellors – Head of Data Engineering [email protected] When not

    to use plumber • Shiny is a better for many users/uses • It’s predominantly for API’s, not a full web stack solution
  11. Mark Sellors – Head of Data Engineering [email protected] Extra things

    to consider... • Security • input sanitisation • logging • monitoring • load balancing and state • blocking
  12. Mark Sellors – Head of Data Engineering [email protected] Old workflow

    •Claim received •Passed to human processing team •Claim is processed •Result decided •Result conveyed to customer
  13. Mark Sellors – Head of Data Engineering [email protected] Easy acceptance

    Easy rejection The tricky middle area Human processing team Claims in How can we optimise?
  14. Mark Sellors – Head of Data Engineering [email protected] New Workflow

    •Claim received •Claim form scanned •OCR performed and converted to XML representation •XML file is passed to an R service •Claim is compared against past claims and scored •Score determines next action: •Immediate payout •Immediate refusal •Passed to processing team for further action
  15. Mark Sellors – Head of Data Engineering [email protected] Workflow •Claim

    received •Claim form scanned •OCR performed and converted to XML representation •XML file is passed to an R service •Claim is compared against past claims and scored •Score determines next action: •Immediate payout •Immediate refusal •Passed to processing team for further action XML file is passed to an R service
  16. Mark Sellors – Head of Data Engineering [email protected] Creating an

    API in R •RServe •OpenCPU •Plumber •DeployR •Domino Data Lab •Others
  17. Mark Sellors – Head of Data Engineering [email protected] > summary(talk)

    •Deploying R as a service (API) is increasingly straightforward •Creating an API provides a simple mechanism for exposing your functions to other users. •Plumber provides a really simple way to quickly create API’s using R •Put the business challenge before the analytic problem