Use Application Mode libraries

This guide shows you how to use the ApplicationState class and the get_app_state function from the deephaven.appmode module in Application Mode scripts. These give you more control over Deephaven's state during launch. The get_app_state function returns the state only during startup; see When the application state is available.

ApplicationState publishes tables and other objects as application fields, which the web IDE and API clients can open. A field is a named object, such as a table, that the server publishes to clients. For more on fields, see Initialize server state with Application Mode.

Example

The following example uses ApplicationState to create tables within Deephaven through Application Mode.

When the application state is available

get_app_state returns the application state only while the files of an Application Mode script run during startup. Calling get_app_state at any other time raises a DHError.

Deephaven runs every file listed in the file_N entries of the Application Mode config file in the same startup run, so each file gets the same ApplicationState. If a script needs to add fields later, it must keep a reference to the ApplicationState.

Add or replace a field

Assign a value to a name on the ApplicationState instance. If a field with that name already exists, the assignment replaces it.

Note

Fields set on ApplicationState appear in the web IDE's Panels menu and are available to API clients, but they are not added to the query scope. To refer to one of these tables by name in console code, also add it to the query scope in the script, for example by assigning it to a global variable.

Read a field

Use the field name as a key to get its value. If no field has that name, the lookup raises a KeyError.

List fields

The fields property of ApplicationState returns a dictionary that maps each field name to its value.

Remove a field

Use del with the field name to remove a field. If no field has that name, the statement raises a KeyError.

Known issues