In episode 13 of the Shiny Developer Series, we continue our conversation with RStudio software engineer Barrett Schloerke to highlight how you can integrate Shiny apps with custom APIs written in R via the plumber package! You’ll see awesome demonstrations of the key features that are part of the brand new plumber 1.0 release, including brand new serializers and parsers for custom objects, a new tidy API compliant with magrittr pipelines, utilizing asynchronous execution, and more.
Resources mentioned in the episode
- plumber allows you to create a web API by merely decorating your existing R source code with roxygen2 style comments.
- Site: https://www.rplumber.io/
- Demos:
- NEW - Hex logo and website!
- NEW - pipe-able programatic interface
- Demo: plumb(dir = "plumber/pipe") %>% pr_run()
- NEW - POST body parsing
- Process incoming POST body data
- Ex: HTML forms, multipart forms, csv, tsv, json, yaml, feather and rds.
- Like serializers, register new POST body parsers
- Site: https://www.rplumber.io/reference/parsers.html
- More Serializers!
- Serialize outgoing route data
- Ex: plain text, json, yaml, csv, tsv, rds, feather
- NEW - Register image serializers: svg, tiff, bmp, pdf. (Pre existing: png, jpeg)
- Site: https://www.rplumber.io/reference/serializers.html
- NEW - Download return values as attachments!
- Site: https://www.rplumber.io/reference/as_attachment.html
- Demo: plumb_api("plumber", "16-attachment") %>% pr_run()
- NEW - Async / promises
- Demo: plumb("plumber/plumber-future.R") %>% pr_run()
- NEW - API UIs (rapidoc)
- Register new User Interfaces to look at your API
- Demo: plumb(dir = "plumber/rapidoc") %>% pr_run()
- Thank you to Bruno Tremblay (@meztez) for his heavy contributions to plumber!
- Recent conference talks about plumber:
- Democratizing R with plumber APIs (James Blair): rstudio.com/resources/rstudioconf-2019/democratizing-r-with-plumber-apis
- Practical plumber patterns (James Blair): rstudio.com/resources/rstudioconf-2020/practical-plumber-patterns/
- Bike Prediction example application with plumber API and Shiny: solutions.rstudio.com/tour/bike_predict/
Episode Timestamps
0:00 - Intro
1:14 - Introduction to plumber
4:14 - Example of plumber API
7:14 - Pipeable interface for plumber
9:19 - plumber's new hex logo!
9:24 - Serializers in plumber
13:04 - Parsers in plumber
14:30 - as_attachment for serializers
15:50 - Demo of downloading an attachment from API
16:07 - A consistent way to check for plumber APIs with available_apis()
18:50 - Async processing in plumber
24:23 - Demo of the plumber documentation UI
29:20 - Example of decoupling data source from Shiny app
29:50 - Episode wrapup