https://github.com/Appsilon/experimental-plumber-example
https://github.com/Appsilon/experimental-plumber-example
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/Appsilon/experimental-plumber-example
- Owner: Appsilon
- Created: 2023-09-22T11:38:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-15T05:30:37.000Z (over 1 year ago)
- Last Synced: 2024-08-13T07:11:13.369Z (8 months ago)
- Language: R
- Size: 134 KB
- Stars: 14
- Watchers: 15
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - Appsilon/experimental-plumber-example - (R)
README
## Plumber Example
> Plumber API paired with a Shiny App that displays data and plots renders in API
The Plumber API implemented in this repository is a simple wrapper over the `EuStockMarkets` dataset allowing to query and plot this dataset.
It shows the potential usages of Plumber by creating a REST api that is async _(handles multiple requests in parallel)_ and caches the results.
#### Plumber technical features:
- Using `{future}` to allow for async requests;
- Using `{memoise}` to allow for caching of the results;
- re-using the results cache on following request with same parameters.#### Endpoints
- `/plot` :: returns HTML that can be embedded in a Web page;
- `/query` :: returns the data that supports the plot;
- `/ranges` :: returns metadata for the available date ranges;
- `/indexes` :: returns metadata that provides the available indexes in the data.##### Example links
Note: it needs `connect.appsilon.com` creadentials.
- API documentation: https://connect.appsilon.com/plumber-example/
- Shiny example (see below): https://connect.appsilon.com/plumber-example-shiny/
- Sample plot: https://connect.appsilon.com/plumber-example/plot?from=1990-01-01&to=2000-01-01
- Sample metadata _(date ranges)_: https://connect.appsilon.com/plumber-example/ranges#### Security
The example also implements a origin validation check when configured.
A secret key shared known only to the Plumber API and the client allows the creation of a token that validates that the requests originated from a trusted source.The example Plumber API is deployed via the Posit Connect infrastructure, which ensures that the traffic is encrypted behind the HTTPS protocol.
#### Load Balancing
Multiple instances of the Plumber API can be run behind a load balancer to provide with more capacity to a stateless service.
For example, this can be achieved via a `Docker`-based solution `haproxy`.
#### Shiny _(paired with Plumber)_
Shiny _(or any other web application)_ can be paired with Plumber to render plots or perform complex data-manipulations.
As an add-on to the plumber example we implement a web application that uses the API for all it's data and plotting needs.
- Calls Plumber API to retrieve metadata
- Plot is rendered by the browser (bypassing Shiny server)
- Using an `iframe` HTML element _(browser calls on Plumber API endpoint and renders it)_
- Shiny process is not blocked by the rendering of the plotA diagram of the communication happening once the page is loaded _(and everytime the parameters are modified)_:
```mermaid
sequenceDiagram;
autonumber
participant Browser
participant Shiny
participant Plumber API
Browser->>Shiny: Open App
Shiny->>Plumber API: Get metadata
Plumber API-->>Shiny: Return metadata
Note over Plumber API,Shiny: Available
"Date ranges" & "Indexes"
Shiny-->>Browser: Render App
Note over Shiny,Browser: Input slider &
Parameters for plot (iframe)
Browser-)Plumber API: GET iframe contents
Plumber API--)Browser: Render Plot
```