Glue42 Enterprise is now io.Connect Desktop! The new documentation site for all interop.io products is located at docs.interop.io.

How to...

Overview

The Glue42 Dash library offers components based on React that enable you to use Glue42 features in your apps built with the Dash framework for Python.

Note that all Glue42 Dash components aren't represented visually and will be invisible in your apps. Their only purpose is to provide access to Glue42 functionalities.

Installation

The Glue42 Dash library is available as a package on the Python Package Index. To install it, execute the following command:

pip install dash_glue42

Referencing

To reference the Glue42 Dash library in your Dash app:

import dash_glue42

When the JavaScript of the library has been loaded, a glue42dash object is attached to the global window object with the following properties:

Property Type Description
glueInstancePromise Promise<object> Resolves with the initialized Glue42 instance. Await this to get the Glue42 instance initialized by the library in order to use it in your own scripts or in client-side callbacks.
glueInstance object The initialized Glue42 instance. If the library hasn't finished initializing, will be undefined.
version string Version of the Glue42 Dash library.
libSettings object Configuration object that allows you to override the Glue42 factory functions and provide a list of Glue42 factory functions that will be initialized internally to provide access to specific functionalities for the Glue42 Dash library from JavaScript code. You can also use this to prevent the Glue42 initialization altogether.

The glue42dash object allows access to the JavaScript Glue42 instance initialized internally by the Glue42 Dash library.

Note that your the HTML template of your app should respect the fact that libraries must be loaded before external scripts. Consider this when structuring the loading sequence of your scripts to avoid cases of failed library initialization.

Initialization

To initialize the Glue42 Dash library, use the Glue42 component and pass an id for it:

import dash
import dash_glue42

app = dash.Dash(__name__)

app.layout = dash_glue42.Glue42(id="glue42")

The Glue42 component has the following properties:

Property Description
id ID of this component. Used to identify Dash components in callbacks. The ID must be unique across all components in an app.
isEnterprise Indicates whether the app is running in Glue42 Enterprise or not. The value of this property is assigned by the framework and must not be altered by client code.
children The children of this component.
settings Optional object containing configurations for the respective Glue42 libraries.
fallback Optional component to display while initializing Glue42.
glueReady Indicates whether the Glue42 library has initialized. The value of this property is assigned by the framework and must not be altered by client code.

Library Configuration

The underlying Glue42 JavaScript library accepts an optional configuration object. The example below demonstrates how to enable the Glue42 Channels API by using the settings property of the Glue42 component when the app is meant to run in Glue42 Enterprise:

import dash
import dash_glue42

glue_settings = {
    # Enabling Channels in Glue42 Enterprise.
    "desktop": {
        "config": {
            "channels": True
        }
    }
}

app = dash.Dash(__name__)

# Initializing the Glue42 library with custom settings.
app.layout = dash_glue42.Glue42(id="glue42", settings=glue_settings, children=[
    # Instantiating the Channels component.
    dash_glue42.Channels(id="glue42-channels")
])

The table below describes the properties of the optional settings object:

Property Description
type Optional. Accepts either "platform" or "client" as a value. Specifies whether this is a Main app or a Web Client in the context of Glue42 Core. The default is "client".
web Optional. An object with one property: config. The config property accepts a configuration object for the Glue42 Web library. You should define this object if your app is a Web Client.
webPlatform Optional. An object with one property: config. The config property accepts a configuration object for the Web Platform library. You should define this object if your app is a Main app in the context of Glue42 Core.
desktop Optional. An object with one property: config. The config property accepts a configuration object for the @glue42/desktop library used in Glue42 Enterprise. You should define this object if your app is a Glue42 Enterprise app.

Note that in Python it isn't possible to pass a function as a value, therefore the properties of the config objects which accept a function as a value can't be set.

Configuration from JavaScript Code

You can also supply configuration settings for the initialization of the Glue42 Dash library from JavaScript code by using the libSettings property of the glue42dash object attached to the global window object. The libSettings object allows you to override the Glue42 factory functions and provide a list of Glue42 factory functions that will be initialized internally to provide access to specific functionalities.

The following example demonstrates how to enable the Glue42 Search API and override the factory function:

import Glue from "@glue42/desktop";
import GlueSearch from "@glue42/search-api";

const settings = {
    desktop: {
        // You may need a specific version.
        factory: Glue,
        libraries: [GlueSearch]
    }
};

window.glue42dash.libsettings = settings;

Preventing Glue42 Initialization

Since the libSettings object enables you to override the Glue42 factory functions, it's possible to entirely skip the initialization of the Glue42 library. This may be useful if your app is meant to run both within and outside of Glue42 Enterprise. To prevent the initialization of the Glue42 library when running outside of Glue42 Enterprise, your factory function override must return an object with a skipInit property set to true.

Note that if the initialization of the Glue42 library has been prevented, the children of the Glue42 component won't have access to Glue42 functionalities. Consider this if you expect Input from a Glue42 Dash component or update a prop from a callback.

Note that the skipInit property is an additional implementation only for Glue42 Dash apps. This property isn't part of the Glue42 JavaScript API.

The following example demonstrates how to determine whether the app is running in Glue42 Enterprise by checking for the glue42gd object attached to the global window object only when the app is running in Glue42 Enterprise. If the app is running outside of Glue42 Enterprise, an override function is provided to prevent the Glue42 initialization:

// Checking for the `glue42gd` object to determine whether the app is running in Glue42 Enterprise.
const inGlue42Enterprise = !!window.glue42gd;

if (inGlue42Enterprise === false) {
    const settings = {
        desktop: {
            // Preventing the Glue42 initialization if not running in Glue42 Enterprise.
            factory: () => Promise.resolve({ skipInit: true })
        }
    };

    window.glue42dash.libSettings = settings;
};

App Configuration

To add your Dash app to the Glue42 Toolbar, you must create a JSON file with app configuration. Place this file in the %LocalAppData%\Tick42\UserData\<ENV>-<REG>\apps folder, where <ENV>-<REG> must be replaced with the environment and region of your Glue42 Enterprise copy (e.g., T42-DEMO).

Note that this step isn't necessary if your app is running in a Glue42 Core project. For more details, see the App Management > App Definitions section in the Glue42 Core documentation.

The following is an example configuration for a Dash app:

{
    "title": "Dash App",
    "type": "window",
    "name": "dash-app",
    "details": {
        "url": "http://127.0.0.1:5000/dash-app",
        "top": 25,
        "left": 800,
        "height": 400,
        "width": 400
    }
}

For more details, see the Developers > Configuration > Application section.

See also the Glue42 Dash examples on GitHub, demonstrating the various Glue42 Enterprise features.

Glue42 Dash Concepts

For more detailed information on the different Glue42 concepts and APIs, see: