Introduction to App Canvas
What is app canvas?
App Canvas is a product that allows apps to define custom user interfaces within Benchling. Interactive Benchling apps can use Canvas “blocks” to create custom UI experiences in the context of a Benchling scientist's workflow, allowing users to interact directly with the app. Best of all, Canvas UIs update in real time, so no waiting and refreshing the page is necessary to get feedback from a Benchling App.
Currently, app canvases can appear in two places: On an app’s homepage, and within interactive assay runs. While the functionality of the canvases is the same in either location, they typically support distinct use cases:
- App homepage canvases are often used for apps that require advanced configuration, or configuration options that vary between tenant installs. App homepage canvases are also common for apps that support “global” actions and settings.
- Interactive assay run canvases are generally used when an app needs to insert a user interface into a notebook entry. This can involve using a lab automation run alongside the canvas UI, or the run can act as “container” to hold the canvas UI (without functioning as a traditional run)
How to design interactive apps
Benchling Apps can vary significantly in complexity and functionality, but most follow the same basic patterns. App Canvas allows for the design of interactive apps, which have some more stringent design requirements. A prototypical interactive app has three key design components:
App manifest with features defined
While a manifest isn’t required for all Benchling apps, it is required for interactive apps that leverage a canvas. An interactive app will define some number of “features”, each of which determine where the custom UI will be provided by the app. Distinct features typically serve distinct purposes, and an interactive app can define as many (or as few) features as appropriate.
Public webhook endpoint
Webhooks are a key component of interactive apps; canvases trigger a variety of app signals that are sent as webhooks including canvas initialization and button click events. Apps using canvases must therefore be able to receive webhooks from Benchling; check out our Getting Started with Webhooks guide for more details.
Application logic for interacting with canvas
Interactive apps define custom user interfaces using canvas blocks, and use the Canvas API to update the canvas contents. Benchling then renders the components in the canvas in realtime. Apps must be capable of responding to canvas webhooks by querying and updating the canvas(es) in question to produce the desired user experience.
How to use app canvas
To use app canvas, your app must be installed from an App Manifest. An interactive app must define at least one feature, which will correspond to where the app intends to render an app canvas. Currently two types of features are supported: ASSAY_RUN
features that introduce a canvas to an interactive run, and APP_HOMEPAGE
features that introduce a canvas to the app’s homepage. An app's features as defined in the manifest might look like this:
features:
- name: Interactive Run Feature
id: test_interactive_run_feature
type: ASSAY_RUN
- name: App Homepage Feature
id: test_app_homepage_feature
type: APP_HOMEPAGE
Each field listed is required:
- The
name
field is the user-facing name of the feature - The
id
field is the app-defined unique identifier for the feature - The
type
field denotes where the feature is available; currently, only theASSAY_RUN
(corresponding to interactive runs) andAPP_HOMEPAGE
types are supported
An app manifest may define any number of
ASSAY_RUN
type features, but at most oneAPP_HOMEPAGE
type feature. This is because there is only one singular place the canvas for anAPP_HOMEPAGE
type feature may be rendered: the app's own workspace page. MultipleAPP_HOMEPAGE
features would imply multiple canvases on this workspace page, which we do not currently support.
Canvas Initialization
With an ASSAY_RUN
feature defined, admins will have the ability to select run schemas where the canvas will appear. This option can be found in the app’s configuration interface; for interactive runs, the user will be able to select a number of run schemas where they would like the UI to render:
App Homepage features work slightly differently; instead of being created alongside an object (like a run) in the notebook, the canvas exists on the General tab of the app in the App Workspace:
In both cases, certain user interaction criteria triggers a canvas initialization webhook:
- For Interactive Run canvases, an initialization webhook is triggered when an instance of a relevant run schema is created in a notebook entry
- For App Homepage canvases, an initialization webhook is sent when the app is activated. The app homepage canvas initialization webhook should arrive shortly after the app install webhook (see the lifecycle section of App Configuration & Lifecycle for more details).
App permissions for creating or updating Canvases
In order for an app to create custom UIs in Benchling via Canvas, it must have sufficient access to the underlying Benchling resource on which the Canvas will be created. In the case of Interactive Run canvases, this means the app must be able to read the assay run that the user created. Apps are always permitted to read themselves, so App Homepage canvases require no additional permissions.
After receiving a canvas initialization webhook, an app must create an initial canvas using the Create an App Canvas endpoint. A canvas initialization webhook looks like this:
{
"app": {
"id": "app_gh8DciACwgm6CtIi"
},
"baseURL": "https://piproduct.benchling.com",
"channel": "app_signals",
"message": {
"featureId": "test_interactive_run_feature",
"resourceId": "412c72a4-421d-449f-1147-7e9154cb3d56",
"deprecated": false,
"excludedProperties": [],
"type": "v0.canvas.initialized"
},
"tenantId": "ten_rhp9gje5mg",
"version": "0"
}
Importantly, the initialization webhook will include a featureId
corresponding to the feature id
defined in the app manifest, as well as a resourceId
indicating the public API identifier of the Benchling resource on which the interaction is happening in the Benchling UI. Both of these properties will be required when the app POST
s an initial canvas. In the above example, the ASSAY_RUN
type feature with ID test_interactive_run_feature
from our earlier example manifest was triggered, and so the resourceId
in the payload is an assay run ID. If instead the APP_HOMEPAGE
type feature had been triggered, the resourceId
in the payload would be the app's API identifier.
ACK webhooks quickly!
An app must acknowledge a canvas webook with a response within 1 second to prevent the UI from timing out, though the app can take longer to
POST
orPATCH
a canvas. Canvas blocks are processed and rendered in the UI in realtime, meaning Benchling users do not need to wait and refresh to see UI updates.
Interaction Webhooks
In addition to initialization webhooks, users interacting with app canvases will also trigger webhooks. Here’s an example of a webhook triggered by a user clicking a button in a canvas:
{
"app": {
"id": "app_gh8DciACwgm6CtIi"
},
"baseURL": "https://piproduct.benchling.com",
"channel": "app_signals",
"message": {
"buttonId": "submit",
"canvasId": "cnvs_0IYfHKi4",
"deprecated": false,
"excludedProperties": [],
"type": "v0.canvas.userInteracted"
},
"tenantId": "ten_rhp9gje5mg",
"v
Interaction webhooks allow the app to respond to user input and update the canvas in real-time. Updating an existing canvas involves using the Update App Canvas endpoint to PATCH the canvas blocks that make up the canvas UI. A list of available canvas blocks can be found in the App Canvas Block Reference.
Updating an app canvas replaces the existing canvas elements with the content provided in the request body; to append blocks to an existing app canvas, the update should include the new block(s) as well as all existing blocks. Here’s an example of updating the example canvas from before to remove the input elements:
PATCH /api/v2/app-canvases/:canvas_id
{
"blocks": [
{
"enabled": true,
"id": "submit",
"text": "Click me to submit",
"type": "BUTTON"
}
],
"enabled": true
}
Updated 3 months ago