Display query creation UI in an Inline Frame

You can embed Deephaven’s query creation UI in an iframe, allowing you to add interactive console query capabilities to your custom web applications. By using the Deephaven JS API alongside the iframe, you can integrate data exploration features directly into your own apps. This guide outlines the steps required to set up and communicate with the embedded query UI.

  1. Load the JS API from the /irisapi/irisapi.nocache.js path of the target Deephaven server.
  2. Log in to the server using the JS API and get a refresh token.
  3. Add an iframe to the page that loads the /iriside/iframecontent/createworker path on the target Deephaven server.
  4. Handle postMessage communication between the current Window and the iframe.

Example App

The following example app presents a custom login page that allows the user to provide a Deephaven server URL and to log in with a username and password.

IFrame Login

Upon successful login, you will be redirected to a query creation form where you can create an interactive console query.

IFrame Create Query

Full Code Example

Download the JS API Dynamically

Once you provide the server URL to the app, it will download the JS API by appending a script tag to the DOM and waiting for its onload event:

Login and get a refresh token

Once the JS API has been loaded, you need to get a refresh token that the iframe can use:

  1. Create a JS API client.
  2. Register to the EVENT_REFRESH_TOKEN_UPDATED event.
  3. Log in to the client with the username / password provided by the user.
  4. Receive the refresh token provided by the next EVENT_REFRESH_TOKEN_UPDATED event.

The example app wraps all of this in a Promise that resolves when the token is received:

Load the iframe

Once a refresh token is received, the app will load an iframe pointing to the Deephaven server's iriside/iframecontent/createworker path.

Handle post messages

Once the iframe has loaded, Deephaven will initiate communication with the containing page via postMessage APIs:

  1. Deephaven will request a refresh token by sending an io.deephaven.message.IframeContent.authTokenRequest message to the parent Window.
  2. The parent Window will respond by sending a message back to the iframe with the same ID as the request and whose payload contains the refresh token.
  3. Deephaven will authenticate with the refresh token. If successful, it will request initialization settings for the UI by sending an io.deephaven.message.IframeContent.settingsRequest message.
  4. The parent window must respond to the settings request, optionally overriding UI settings.

Once the entire sequence of messages is successful, you should be presented with a form that can be used to create interactive queries. Select your desired settings and click Connect. Once the query is created, Deephaven will send an io.deephaven.message.IframeContent.workerCreated message to the parent Window containing the serial ID for the query. The example code will write this to the console.log.

Settings API

The message passed to the iframe in response to the io.deephaven.message.IframeContent.settingsRequest message is required to complete the UI initialization.

While the minimal required payload is an empty object, you will likely want to configure the UI. The payload supports the following optional settings:

  • newWorkerName - the name of the interactive query that will be created. Note that this needs to be unique every time it is provided. In the example, it is generated as IframeContentTester - Create Worker - ${crypto.randomUUID()}
  • isLegacyWorkerKindSupported - determines if legacy worker types are included in the Engine dropdown. Defaults to true
  • showHeader - whether to show the New Console Connection header. Defaults to true for legacy reasons, but typically should be set to false
  • settings - can be used to define the default values of form fields in the query creation UI. These correspond to the payload sent by io.deephaven.message.IframeContent.settingsChanged messages any time the UI fields are updated by a user.