Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Creating API's with R and plumber

3 744 vues

Publié le

Slides from my recent talk at the LondonR user group (http://www.londonr.org) on creating API's with R and the 'plumber' package

Publié dans : Technologie
  • Soyez le premier à commenter

Creating API's with R and plumber

  1. 1. Mark Sellors - Technical Architect msellors@mango-solutions.com APIs with R and plumber Mark Sellors - Mango Solutions
  2. 2. Mark Sellors - Technical Architect msellors@mango-solutions.com Me • Technical Architect • Data Engineering • DataOps • Analytic Maturity • Automation • Industrialisation
  3. 3. Mark Sellors - Technical Architect msellors@mango-solutions.com Agenda • API’s • Introducing plumber • How it works • A simple case study • Caveats • Summary
  4. 4. Mark Sellors - Technical Architect msellors@mango-solutions.com Data Science + API’s are Changing the World
  5. 5. Mark Sellors - Technical Architect msellors@mango-solutions.com Introducing plumber http://plumber.trestletech.com
  6. 6. Mark Sellors - Technical Architect msellors@mango-solutions.com Example - simple function > adder <- function(a, b){ + a + b + } > adder(4, 3) [1] 7
  7. 7. Mark Sellors - Technical Architect msellors@mango-solutions.com Example - add plumber #* @get /adder > adder <- function(a, b){ + as.numeric(a) + as.numeric(b) + }
  8. 8. Mark Sellors - Technical Architect msellors@mango-solutions.com Example - running with plumber > library(plumber) > r <- plumb("my_api_file.R") > r$run(port=8000)
  9. 9. Mark Sellors - Technical Architect msellors@mango-solutions.com Example - Accessing the API # curl http://localhost:8000/adder?a=4&b=3
  10. 10. Mark Sellors - Technical Architect msellors@mango-solutions.com Demo 1 - Simple API
  11. 11. Mark Sellors - Technical Architect msellors@mango-solutions.com Example - serving graphs
  12. 12. Mark Sellors - Technical Architect msellors@mango-solutions.com Demo 2 - Tick API
  13. 13. Mark Sellors - Technical Architect msellors@mango-solutions.com Why? What’s the point?
  14. 14. Mark Sellors - Technical Architect msellors@mango-solutions.com Example - Shiny App
  15. 15. Mark Sellors - Technical Architect msellors@mango-solutions.com Demo 3 - Currency Converter
  16. 16. Mark Sellors - Technical Architect msellors@mango-solutions.com 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
  17. 17. Mark Sellors - Technical Architect msellors@mango-solutions.com Demo 4 - Currency API
  18. 18. Mark Sellors - Technical Architect msellors@mango-solutions.com Caveats
  19. 19. Mark Sellors - Technical Architect msellors@mango-solutions.com 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
  20. 20. Mark Sellors - Technical Architect msellors@mango-solutions.com Extra things to consider... • Security • input sanitisation • logging • monitoring • load balancing and state • blocking
  21. 21. Mark Sellors - Technical Architect msellors@mango-solutions.com The Competition RServe OpenCPU DeployR Domino Others?
  22. 22. Mark Sellors - Technical Architect msellors@mango-solutions.com Conclusion 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

×