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