Python web application framework for building reactive analytical web apps without JavaScript
npx @tessl/cli install tessl/pypi-dash@3.2.0Dash is a Python web application framework for building reactive analytical web applications. Built on top of Plotly.js, React, and Flask, Dash enables data scientists and analysts to build interactive web apps using pure Python without requiring JavaScript knowledge.
pip install dashimport dash
from dash import Dash, dcc, html, dash_table, Input, Output, State, callbackCommon patterns:
from dash import Dash, html, dcc, callback, Input, Output, Statefrom dash import Dash, html, dcc, callback, Input, Output
import plotly.express as px
# Initialize the app
app = Dash(__name__)
# Define the layout
app.layout = html.Div([
html.H1("Hello Dash"),
html.Div("Select a value:"),
dcc.Dropdown(
id='dropdown',
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': 'Montreal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
value='NYC'
),
html.Div(id='output-container')
])
# Define callback
@callback(
Output('output-container', 'children'),
Input('dropdown', 'value')
)
def update_output(value):
return f'You have selected {value}'
if __name__ == '__main__':
app.run(debug=True)Dash follows a reactive programming model with these key components:
Main Dash application class for creating and configuring web applications with layout management, callback registration, and server integration.
class Dash:
def __init__(
self,
name: str = None,
server: Any = None,
assets_folder: str = 'assets',
pages_folder: str = 'pages',
use_pages: bool = None,
assets_url_path: str = '/assets/',
assets_ignore: str = '',
external_scripts: List[Union[str, Dict]] = None,
external_stylesheets: List[Union[str, Dict]] = None,
suppress_callback_exceptions: bool = None,
prevent_initial_callbacks: bool = None,
show_undo_redo: bool = False,
plugins: List = None,
title: str = 'Dash',
update_title: str = 'Updating...',
**kwargs
): ...
def run(self, debug: bool = None, port: int = 8050, host: str = '127.0.0.1', **kwargs): ...
def callback(self, *args, **kwargs): ...
def clientside_callback(self, clientside_function, output, inputs, state=None, **kwargs): ...Reactive programming system that connects user interactions to data updates through Input/Output dependencies and callback functions.
class Input:
def __init__(self, component_id: Union[str, Dict], component_property: str): ...
class Output:
def __init__(self, component_id: Union[str, Dict], component_property: str): ...
class State:
def __init__(self, component_id: Union[str, Dict], component_property: str): ...
class ClientsideFunction:
def __init__(self, namespace: str, function_name: str): ...
def callback(*args, **kwargs): ...
def clientside_callback(clientside_function, output, inputs, state=None, **kwargs): ...
# Wildcard patterns
MATCH: Any # Match any ID in pattern-matching callbacks
ALL: Any # Match all IDs in pattern-matching callbacks
ALLSMALLER: Any # Match all smaller indices in pattern-matching callbacksComprehensive component ecosystem including core components (dcc), HTML elements (html), and data tables (dash_table).
# Dash Core Components (dcc)
class Graph(Component): ...
class Dropdown(Component): ...
class Slider(Component): ...
class Input(Component): ...
class Store(Component): ...
class Location(Component): ...
class Link(Component): ...
# Dash HTML Components (html)
class Div(Component): ...
class H1(Component): ...
class Button(Component): ...
class A(Component): ...
class P(Component): ...
# Dash DataTable
class DataTable(Component): ...Built-in support for single-page application (SPA) navigation with automatic routing, page registration, and SEO optimization.
def register_page(
module: str = None,
path: str = None,
path_template: str = None,
name: str = None,
order: Union[int, float] = None,
title: str = None,
description: str = None,
image: str = None,
redirect_from: List[str] = None,
layout: Any = None,
**kwargs
): ...
page_registry: Dict[str, Any] # Registry of all registered pages
page_container: Component # Container component for page contentSpecial values and utilities for controlling callback execution and component updates.
class NoUpdate:
"""Sentinel value to prevent component updates."""
pass
no_update: NoUpdate # Alias for NoUpdate()
class PreventUpdate(Exception):
"""Exception to prevent callback execution."""
pass
class Patch:
"""Partial updates for lists and dictionaries."""
def append(self, item): ...
def prepend(self, item): ...
def insert(self, index: int, item): ...
def remove(self, item): ...
def clear(self): ...Asynchronous callback processing for long-running operations with progress reporting and caching support.
class CeleryManager:
def __init__(self, celery_app): ...
class DiskcacheManager:
def __init__(self, cache_by: str = "session", cache: Any = None): ...
# Background callback decorator
@callback(
background=True,
manager=CeleryManager(celery_app),
running=[(Output("loading", "children"), "Running...")],
progress=[Output("progress", "value"), Output("progress", "max")],
progress_default=[0, 100]
)
def long_running_callback(*args): ...Static asset handling including CSS, JavaScript, images, and external resources with hot reloading and fingerprinting.
def get_asset_url(path: str) -> str:
"""Get URL for asset file."""
...
def get_relative_path(path: str) -> str:
"""Get relative path from request."""
...
def strip_relative_path(path: str) -> str:
"""Strip relative path prefix."""
...# Core types
Component = Any # Base component class
ComponentIdType = Union[str, Dict, Component] # Component identifier
LayoutType = Union[Component, List, Dict, str, int, float] # Layout content
# Callback types
CallbackContext = Any # Callback execution context
CallbackFunction = Callable[..., Any] # Callback function signature
DependencyList = List[Union[Input, Output, State]] # Callback dependencies
# App configuration
ServerType = Any # Flask server instance
AssetList = List[Union[str, Dict[str, str]]] # External assets
PluginList = List[Any] # Plugin instances
# Multi-page types
PageConfig = Dict[str, Any] # Page configuration
PageRegistry = Dict[str, PageConfig] # Page registry