dash module#

The dash module in the visualization_toolkit contains common abstractions to launch dash apps with best practices. The functions can assist with generating queries, caching results, tracking user interactions and more.

Many components offered in the dash module are built with yipit-dash-mui-components.

Core Component Functions#

Functions that generate Dash components that are commonly needed in building data apps.

visualization_toolkit.helpers.dash.chart_component(index, height=YD_CLASSIC_THEME['layout']['height'], graph_config_overrides=None, clear_on_unhover=False)[source]#

Returns a charting component for plotly figures with built-in dcc.Loader to handle the intermediate querying state gracefully. Using this component requires specifying the chart component ID as an index, and this index is used to populate the underlying plotly figure in a separate callback.

The loader will use the ymc.Skeleton component as a placeholder when the chart is not ready to be displayed.

When defining callbacks using this component, use pattern-matching callback syntax. The index will match the supplied id value. The type of each subcomponent is the following:

  • chart: Accesses the dcc.Graph object that holds the chart visual

  • chart-loader: Accesses the dcc.Loading object that managers the loading state

Important to note that, it requires that a callback modify the loader component’s display parameter to hide. This will remove the loader and display the underlying plotly figure.

Parameters:
  • index (str) – The index of the chart, should be unique to the chart within a Dash app. The index will be used in the subcomponents and referenced in callbacks.

  • height (Optional[int]) – Optionally specify the height of the graph object, will default to the standard theme height if not specified.

  • graph_config_overrides (Optional[dict]) – Optionally specify a dictionary of plotly chart configuration options, these will override the base PLOTLY_CHART_CONFIG set by the library.

  • clear_on_unhover (bool) – Optionally specify whether the hoverData should be cleared when the mouse is not hovering over it.

Returns:

dcc.Loading component with an empty plotly figure graph as its children.

Return type:

dash.dcc.Loading

Examples#

Example creating a chart component that uses the loader initially and later be switched to render a graph via callback.#
from dash import Output, Input
from visualization_toolkit.helpers.dash import chart_component
from visualization_toolkit.helpers.plotly import chart

app.layout = [
    chart_component(
        index="example-graph",
    )
]

@app.callback(
    Output({"type": "chart", "index": "example-chart"}, "figure"),
    Output({"type": "chart-loader", "index": "example-chart"}, "display"),  # Accesses the loader display parameter to hide once graph is ready
    Input({"type": "chart", "index": "example-chart"}, "id"),
    running=[
        (Output({"type": "chart-loader", "index": "example-chart"}, "display"), "show", "hide"),
    ],
)
def display_graph(_):
    fig = chart(...)  # Custom logic to generate plotly figure
    return fig, "hide"  # "hide" tells the loader to hide and show the graph instead
visualization_toolkit.helpers.dash.custom_tooltip_callback(tooltip_id, chart_id, x_offset=100, y_offset=0, x_buffer=100, y_buffer=100, tooltip_min_width=300, tooltip_min_height=300, debug=False)[source]#

Enable custom tooltip to hover over a chart where the mouse is located.

Warning

When exiting a chart, the tooltip will not be visible. But this requires setting the clear_on_unhover parameter to True in the chart_component component.

Parameters:
  • tooltip_id (str | dict) – The id of the tooltip component. Tooltip should be a ymc.Box or equivalent object that has fixed positioning.

  • chart_id (str | dict) – The id of the chart component (dcc.Graph object)

  • x_offset (int) – The amount in pixels to offset the tooltip from the mouse location horizontally.

  • y_offset (int) – The amount in pixels to offset the tooltip from the mouse location vertically.

  • x_buffer (int) – The amount in pixels to pad the left and right edges of the chart to prevent tooltip from overflowing.

  • y_buffer (int) – The amount in pixels to pad the top and bottom edges of the chart to prevent tooltip from overflowing.

  • tooltip_min_width (int) – The minimum width of the tooltip to account for use in positioning.

  • tooltip_min_height (int) – The minimum height of the tooltip to account for use in positioning.

  • debug (bool)

Returns:

None

Examples#

Example of a custom tooltip callback#
from dash import Output, Input, State
from visualization_toolkit.helpers.dash import chart_component, custom_tooltip_callback

app.layout = [
    ymc.Box(
        id="example-tooltip",
        children=[],
        # Important styling to ensure tooltip is hidden but can be positioned on charts dynamically
        sx={"position": "fixed", "top": 0, "left": 0, "zIndex": 1000},
    ),
    chart_component(
        index="example-chart",
        clear_on_unhover=True,
    ),
    custom_tooltip_callback(
        tooltip_id="example-tooltip",
        chart_id="example-chart",
    )
]

@app.callback(
    Output("example-tooltip", "children"),
    Input("example-tooltip", "id"),
    Input("example-chart", "hoverData"),
    State("example-chart", "id"),
)
def update_tooltip(_, hover_data, chart_id):
    if hover_data:
        # Update the tooltip children based on hover data and other plotly chart information
        return []

    return []

Core Dash Functions#

Functions that are generic utilities for working with Dash apps.

visualization_toolkit.helpers.dash.initialize_app(name, **kwargs)[source]#

Intialize a Dash app with settings tuned for production scenarios. Settings enabled: * Load Google fonts for use with YD theme * Load custom plotly bundle to reduce bundle size * Enable compression of JS assets served * Use CDN when serving static files (enabled when DEBUG mode is off) * Change base html file to remove unnecessary CSS styles

Parameters:
  • name (str) – Name of the dash app to initialize

  • kwargs – Optional kwargs that will be passed to the Dash class instance

Returns:

CustomDash instance that is a subclass of Dash

Return type:

CustomDash

visualization_toolkit.helpers.dash.get_triggered_id(index=0)[source]#

Returns the HTML ID for the triggered element within a dash callback

Parameters:

index (int) – index of triggered input element to get ID for. Defaults to 0 or first triggered eement

Returns:

str

Return type:

str | dict

visualization_toolkit.helpers.dash.resolve_html_id(component)[source]#

Returns the true HTML ID for a given component, ID, or patten-matching ID This can be useful when working in JS, as Dash will sometimes mutate the ID passed in to a component

Parameters:

component (str | dict) – Input element or string to generate the HTML ID

Returns:

Return type:

str

Core Databricks Functions#

Functions to handle connecting to Databricks to execute queries and other spark interactions.

visualization_toolkit.helpers.dash.execute_query(query, sources=None, use_cache=False, overwrite_cache=False, cache_uri=None, return_type='list')[source]#

Execute a SQL query and return the query results. This function includes utilities to cache query results offline to avoid re-running them on the warehouse and improve performance / reduce costs.

When running the function make sure the following environment variables are set to connect to Databricks: - DATABRICKS_SERVER_HOSTNAME: Workspace URL that the SQL Warehouse resides in - DATABRICKS_HTTP_PATH: Path for the given SQL Warehouse to use - DATABRICKS_ACCESS_TOKEN: API token for a given Service Principal that should be used to authenticate to Databricks

Parameters:
  • query (str) – SQL query string to execute

  • sources (list[dict | str]) – List of query source tables that are used in the query. Specify this is required if caching query results as the offline cache will use this to index the results.

  • use_cache (bool) – When True, any query results retrieved from the warehouse will be cached offline. If the query is executed again, the offline cache will retrieve results instead of executing on the SQL warehouse.

  • overwrite_cache (bool) – When True, cached results will not be fetched and the query will be excuted on the warehouse and overwrite the offline cache. This should only be used for maintenance purposes to fix the cache.

  • cache_uri (str) – Optional redis URI for the cache_uri to use. Will default to the ATLAS_CACHE_URI environment variable if not specified. If not specified, caching will not be enabled.

  • return_type (Literal['list', 'pandas_dataframe']) – Optionally control whether results are returned as a list of dictionaries or as a pandas dataframe (pandas_dataframe). Default is list of dictionaries returned.

Returns:

List of query results for the query. When return_type==list, results are returned as a list of dictionaries. Each dict is a row of the query. When return_type == pandas_dataframe, a pd.DataFrame` will be returned.

Return type:

list[dict] | pandas.DataFrame

visualization_toolkit.helpers.dash.get_spark_session()[source]#

Create a pyspark.SparkSession to execute queries on databricks via spark-connect. This should be used when pyspark is necessary for a data app and comes with trade-offs:

  • pyspark is more powerful in generating transformations dynamically

  • spark-connect however has less caching and concurrency capabilities than databricks SQL.

  • spark-connect can also be more costly than databricks SQL.

To use a pyspark session locally, set YDBC_DEPLOYMENT_NAME, YDBC_OAUTH_CLIENT_ID, and YDBC_OAUTH_SECRET as environment variables. These are typically set via infisical by the Platform Engineering team.

Returns:

Return type:

pyspark.sql.connect.session.SparkSession

Core Query Template Functions#

Functions to templatize queries via Jinja2. These can be useful to make query logic more dynamic in data apps.

visualization_toolkit.helpers.dash.sql_query_from_template(template_string, parameters, sources)[source]#

Use Jinja2 to generate a SQL query string given a template string, parameters, and sources (tables).

Parameters:
  • template_string (str) – Jinja2 template passed in as a string

  • parameters (dict) – Key value pairs of parameters to pass to the template. In the template these can be accessed as parameters.<key>. Any JSON compatible data types are allowed.

  • sources (list[dict | str]) – List of table sources passed in to the query template.

Returns:

SQL query that is the output of the template + parameters + sources

Return type:

str

Core Export Functions#

Functions to enable file downloads of data components, including charts and tables.

visualization_toolkit.helpers.dash.export_chart_button_component(index)[source]#

Adds a button + dropdown to download a given chart’s data. This function is intended to be used with the chart_component function.

Export buttons should be placed in the top-right section of a ymc.ChartCardHeader. Typically inside the ymc.ChartCartControls

Parameters:

index (str) – Index to set for the subcomponents of the chart button. This should match the index passed into the corresponding chart_component.

Returns:

Examples#

Example of adding a chart component to a chart card with an export button in the chart controls.#
from visualization_toolkit.helpers.dash import setup_chart_exports, ymc

app = Dash(__name__)

# Create a dash app with a chart and an export chart button
app.layout = [
    ymc.YipitMUIProvider(
        children=ymc.ChartCard([
            ymc.ChartCardHeader([
                ymc.ChartCartControls([
                    export_chart_component(index="example-chart"),
                ]),
            ]),
            chart_component(index="example-chart"),
        ]),
    )
]

# enable export functionality via callbacks
setup_chart_exports(app)
visualization_toolkit.helpers.dash.setup_chart_exports(app)[source]#

Sets up file exports for each chart in a dash app that is using the standard chart_component. In addition, the dash app must include the export_chart_button component for each chart that needs to support exports.

A dropdown will then appear with options to export a chart data as CSV or XLSX files.

Parameters:

app (dash.Dash)

Returns:

Examples#

Example of enabling chart downloads for a dash page with a given chart and export button.#
from visualization_toolkit.helpers.dash import setup_chart_exports, ymc

app = Dash(__name__)

# Create a dash app with a chart and an export chart button
app.layout = [
    ymc.YipitMUIProvider(
        children=ymc.Box([
            chart_component(index="example-chart"),
            export_chart_component(index="example-chart"),
        ]),
    )
]

# enable export functionality via callbacks
setup_chart_exports(app)

Core Analytics Functions#

Functions to track user activity within the dash app. These can augment dash components to track when elements are visible, clicked on, and more. Most of these actions are tracked on the browser through dash client-side callbacks.

Most of these functions will require enabling a user_store and visibility_store in addition to initializing a pendo client via pendo_initialize_callback.

visualization_toolkit.helpers.dash.user_store(user_id='NOT_SET', account_id='NOT_SET', user_metadata=None, account_metadata=None, storage_type='memory', id=ATLAS_USER_STORE_ID)[source]#

Standard object to store user information as it relates to analytics services (ex: pendo). Requires passing in a User ID and Account ID that will then be annotated with any analytics events fired by the dash app.

To keep this data available in a dash app session it will be store clientside using the browsers memory or session

Parameters:
  • user_id (str) – User ID associated with this browser session, typically an email

  • account_id (str) – Account ID associated with the user_id

  • user_metadata (dict[str, str]) – Optional metadata for the user in key/value pairs of a dictionary

  • account_metadata (dict[str, str]) – Optional metadata for the account in key/value pairs of a dictionary

  • storage_type (str) – Optionally control browser side storage behavior. This is passed to the dcc.Store storage_type parameter.

  • id (str) – Optionally set an HTML ID for this instead of the default. Note when setting this, all other callbacks connected to this ID must be updated to reference the new/non-default value.

Returns:

Return type:

dash.dcc.Store

visualization_toolkit.helpers.dash.visibility_store(html_ids=None, storage_type='memory', id=ATLAS_VISIBILITY_STORE_ID)[source]#

Initialize a store to keep track of which elements should emit events when they are visible or not visible on the screen. This should be used with pendo_visible_elements_callback which will access this store to monitor the associated HTML IDs.

Parameters:
  • html_ids (list[str]) – List of HTML IDs to initialize the store with. This list should be the list of HTML elements to be tracked for visibility events

  • storage_type (str)

  • id (str)

Returns:

visualization_toolkit.helpers.dash.control_store(storage_type='memory', id=ATLAS_VISIBILITY_STORE_ID, initial_data=None)[source]#

Initialize a store to keep track of controls and their current values on a page. A separate callback should be implemented to update the control store when any control value changes

Parameters:
  • storage_type (str)

  • id (str) – HTML ID to identify store in dash callbacks

  • initial_data (list | dict) – Initial state of store, typically a list

Returns:

visualization_toolkit.helpers.dash.pendo_initialize_callback(app, user_store_id=ATLAS_USER_STORE_ID, debug=ATLAS_DEBUG)[source]#

Client Side callback to initialize a Pendo session. Once the session is initialized other client-side callbacks to send Pendo events can be executed. This should be used in conjunction with the user_store component. The data from that component will be used in initializing the Pendo session

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • user_store_id (str) – HTML ID of the user store that contains user/account information to initialize Pendo client. Must be associated with a dcc.Store component.

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

Returns:

visualization_toolkit.helpers.dash.pendo_track_click_callback(app, button_id, page, feature, event, additional_properties=None, store_ids=None, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=True)[source]#

Client Side callback to emit a click event every time a ``ymc.Button` is clicked.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • button_id (str | dict) – HTML ID of the corresponding button that is interacted with.

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to True.

Returns:

visualization_toolkit.helpers.dash.pendo_track_input_callback(app, input_id, page, feature, event, additional_properties=None, store_ids=None, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=True)[source]#

Client Side callback to emit an input event when a ``ymc.TextField` is interacted with.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • input_id (str | dict) – HTML ID of the corresponding textfield component that is interacted with.

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to True.

Returns:

visualization_toolkit.helpers.dash.pendo_track_select_callback(app, select_id, page, feature, event, additional_properties=None, store_ids=None, is_multi_select=False, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=True)[source]#

Client Side callback to emit a click event every time a ymc.Select` or `ymc.MultiSelect` or ``ymc.DatePicker options are chosen.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • select_id (str | dict) – HTML ID of the corresponding dropdown component that is interacted with.

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • is_multi_select (bool) – Set to True if a ymc.MultiSelect is used

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to True.

Returns:

visualization_toolkit.helpers.dash.pendo_track_select_range_callback(app, select_range_id, page, feature, event, additional_properties=None, store_ids=None, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=True)[source]#

Client Side callback to emit a click event every time a ``ymc.DateRangePicker` options are chosen.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • select_range_id (str | dict) – HTML ID of the corresponding date range or range component that is interacted with.

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to True.

Returns:

visualization_toolkit.helpers.dash.pendo_track_visible_elements_callback(app, page, feature, event, additional_properties=None, visibility_store_id=ATLAS_VISIBILITY_STORE_ID, store_ids=None, data_context=DASHBOARD_INTERACTION, feature_mapping=None, debug=ATLAS_DEBUG, prevent_initial_call=None)[source]#

Client Side callback to emit an event every time the given html element(s) are visible on screen and also when it exits the viewport

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • visibility_store_id (str) – Store ID that contains the list of HTML IDs to be observing.

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • feature_mapping (dict) – Optional mapping if different html IDs that are tracked are mapped to different pendo features. Keys are HTML IDs and the values are the corresponding feature(s). If not specified, the feature argument is used.

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to None.

Returns:

visualization_toolkit.helpers.dash.pendo_track_table_sort_callback(app, table_id, page, feature, event, additional_properties=None, store_ids=None, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=True)[source]#

Client Side callback to emit a click event every time a ``ymc.DataGrid` is sorted on a column.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • table_id (str | dict) – HTML ID of the corresponding ymc.DataGrid that is interacted with.

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to True.

Returns:

visualization_toolkit.helpers.dash.pendo_track_table_filter_callback(app, table_id, page, feature, event, additional_properties=None, store_ids=None, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=True)[source]#

Client Side callback to emit a click event every time a ``ymc.DataGrid` is filtered on a column.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • table_id (str | dict) – HTML ID of the corresponding ymc.DataGrid that is interacted with.

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to True.

Returns:

visualization_toolkit.helpers.dash.pendo_track_page_load_callback(app, html_id, page, feature, event, additional_properties=None, store_ids=None, data_context=DASHBOARD_INTERACTION, debug=ATLAS_DEBUG, prevent_initial_call=None)[source]#

Client Side callback to emit a load event once the application is fully loaded. This should generally be called once for a data app.

Parameters:
  • app (dash.Dash) – Dash app to register the client side callback

  • html_id (str | dict) – HTML ID of the corresponding element that triggers this callback

  • page (str) – Pendo Page ID for the click action

  • feature (str) – Pendo Feature ID for the click action

  • event (str) – Pendo Event ID for the click action

  • additional_properties (dict) – Optional key value metadata pairs to pass into the Pendo event

  • store_ids (list[str | dict]) – List of optional dcc.Store IDs to store metadata from in track events

  • data_context (str) – Optional metadata to pass into the data_context field of pendo track events

  • debug (bool) – When True, the client side callback will log additional information to the browser console. By default, this is False and should not be used outside of development.

  • prevent_initial_call (bool) – When True, the client side callback will not be fired when associated component initially loads. Defaults to None.

Returns:

Core Celery Functions#

Helper functions to integrate dash applications with celery. Commonly used in production deployments of dash.

visualization_toolkit.helpers.dash.setup_celery_app(name, broker_uri, results_backend_uri=None, celery_app_kwargs=None, celery_manager_kwargs=None)[source]#

Intialize a celery application which is needed if using background callbacks with Dash. Generally this is a preferred setup for production dash applications.

Examples#

Example of setting up a celery app with background callback caching#
import uuid
from visualization_toolkit.helpers.dash import setup_celery_app
from visualization_toolkit.constants import APP_ENVIRONMENT

# Use a different cache_by logic based on the needs of the dash application
launch_uid = str(uuid.uuid4())
celery_app, celery_app_manager = setup_celery_app(
    name=__name__,
    broker_uri=APP_ENVIRONMENT.get("REDIS_URI"),
    celery_manager_kwargs={
        "cache_by": [lambda: launch_uid],
    },
)
param name:

Celery application name

param broker_uri:

Redis URI to use as the celery broker

param results_backend_uri:

Optional URI to use as the celery results backend. This will default to broker_uri if not set. Either redis or postgres can be used.

param celery_app_kwargs:

Additional keyword arguments to pass to the celery app.

param celery_manager_kwargs:

Additional keyword arguments to pass to the celery manager.

return:

Tuple containing the celery app and the cellery callback manager. Both of which are used in backgorund callbacks in Dash.

Parameters:
  • name (str)

  • broker_uri (str)

  • results_backend_uri (str)

  • celery_app_kwargs (dict)

  • celery_manager_kwargs (dict)

Return type:

(celery.Celery, dash.CeleryManager)

Core System Monitoring Functions#

Helper functions to setup production monitoring of a dash app. These will be necesary for deployments in the Cloud.

visualization_toolkit.helpers.dash.setup_sentry(env=None, env_var='SENTRY_DSN')[source]#

Intialize sentry tracking of exceptions. Will connect to sentry via the SENTRY_DSN variable set in the app environment.

Parameters:
  • env (envelop.Environment) – Enveleop Environment client to use. Defaults to the libraries APP_ENVIRONMENT. Generally not needed to be set.

  • env_var (str) – Environment variable name that stores the sentry dsn. Defaults to SENTRY_DSN.

Returns:

visualization_toolkit.helpers.dash.setup_datadog()[source]#

Initialize datadog APM tracing of the dash app. :return:

visualization_toolkit.helpers.dash.setup_healthcheck(server)[source]#

Adds a custom healthcheck endpoint on the dash app required for deployments to AWS. Healthcheck endpoint will return a 200 and is found on /status/healthcheck/

Parameters:

server (flask.Flask | dash.Dash) – Flask server. Generally this is accessed via the server attribute on an initialized dash app. Dash app can also be passed in and the server is retrieved inside the function.

Returns: