REST API that receives write and read requests for telemetry data from a Shiny Dashboard (using
shiny.telemetry
R 📦)
This plumber REST API serves as a middleware between a Shiny Application that is being monitored by shiny.telemetry
and a data backend that write the logging information to persistent storage.
The data backend is provided by the shiny.telemetry
R package.
Features:
- Supports all data storage backends available to
shiny.telemetry
- Validates origin of messages by signing message (see section below)
- Supports secure communication when API is deployed in a server that supports Hypertext Transfer Protocol Secure (HTTPS)
To get a minimal Plumber instance running locally it requires an R
environment (at least ≥v4.1
) and the renv
R package.
Start by downloading or cloning the source files in the repository and open an R session on the /plumber_rest_api
directory.
Install the required packages by calling renv::restore()
inside the R session.
> renv::restore()
Start the Plumber API by sourcing plumber.R
file or by calling plumber::plumb("plumber.R")
.
> # source("plumber.R")
> plumber::plumb("plumber.R")
The plumber instance is now running and the API documentation can be accessed via 127.0.0.1:8087/docs/. The /health_check
endpoint can be used without any parameters.
In order to test as a shiny.telemetry
data storage provider, you can run the code below in an R session.
The example will:
- Create an instance of the
DataStoragePlumber
R6 class configured to use the local Plumber instance - Manually log several pieces of information:
- Login
- 2 Clicks
- Session detail
- Read the action and session logs
- note the timestamps
library(shiny.telemetry)
data_storage <- DataStoragePlumber$new(
username = "test_user",
hostname = "127.0.0.1",
port = 8087,
protocol = "http"
)
log_login(data_storage)
log_click(data_storage, "an_id")
log_click(data_storage, "a_different_id")
data_storage$read_event_data("2020-01-01", "2035-01-01")
As a security feature, it is possible to sign the messages exchanged between shiny.telemetry
and this API so that we can guarantee that only un-modified information from known sources are stored.
The method uses a secret token that is defined as an environment variable on both the Shiny application and in the deployed API. The API can support multiple tokens and by default it uses no signature, so this feature is disabled.
In technical terms, the parameters of the requests are transmitted in plain text with the signature (of the parameters) and an unique identifier of the secret that is being used.
Note that, the data in the message being transmitted via the HTTP protocol is not encrypted (consider using https for this purpose).
To setup the message signature it is required to define:
- In the Plumber API Environment:
SECRET_TOKENS="<string-token-a> <string-token-b>
- In the Shiny Application instrumented by
shiny.telemetry
:PLUMBER_SECRET=<string-token-a>
- In this case, for "Shiny Application A"
ℹ️ Important: the different tokens defined in the API are separated by spaces.
Appsilon is a Posit (formerly RStudio) Full Service Certified Partner.
Learn more at appsilon.com.
Get in touch [email protected]
Check the Rhinoverse.