Python web application framework for building reactive analytical web apps without JavaScript
npx @tessl/cli install tessl/pypi-dash@3.2.00
# Dash
1
2
Dash 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.
3
4
## Package Information
5
6
- **Package Name**: dash
7
- **Language**: Python
8
- **Installation**: `pip install dash`
9
10
## Core Imports
11
12
```python
13
import dash
14
from dash import Dash, dcc, html, dash_table, Input, Output, State, callback
15
```
16
17
Common patterns:
18
19
```python
20
from dash import Dash, html, dcc, callback, Input, Output, State
21
```
22
23
## Basic Usage
24
25
```python
26
from dash import Dash, html, dcc, callback, Input, Output
27
import plotly.express as px
28
29
# Initialize the app
30
app = Dash(__name__)
31
32
# Define the layout
33
app.layout = html.Div([
34
html.H1("Hello Dash"),
35
html.Div("Select a value:"),
36
dcc.Dropdown(
37
id='dropdown',
38
options=[
39
{'label': 'New York City', 'value': 'NYC'},
40
{'label': 'Montreal', 'value': 'MTL'},
41
{'label': 'San Francisco', 'value': 'SF'}
42
],
43
value='NYC'
44
),
45
html.Div(id='output-container')
46
])
47
48
# Define callback
49
@callback(
50
Output('output-container', 'children'),
51
Input('dropdown', 'value')
52
)
53
def update_output(value):
54
return f'You have selected {value}'
55
56
if __name__ == '__main__':
57
app.run(debug=True)
58
```
59
60
## Architecture
61
62
Dash follows a reactive programming model with these key components:
63
64
- **Dash App**: Central application instance managing server, layout, and callbacks
65
- **Layout System**: Hierarchical component tree defining UI structure using dcc, html, and custom components
66
- **Callback System**: Reactive functions that update components based on user interactions
67
- **Component Libraries**: Rich ecosystem of interactive components (graphs, inputs, tables, etc.)
68
- **Server Integration**: Built on Flask for production deployment and extensibility
69
70
## Capabilities
71
72
### Core Application
73
74
Main Dash application class for creating and configuring web applications with layout management, callback registration, and server integration.
75
76
```python { .api }
77
class Dash:
78
def __init__(
79
self,
80
name: str = None,
81
server: Any = None,
82
assets_folder: str = 'assets',
83
pages_folder: str = 'pages',
84
use_pages: bool = None,
85
assets_url_path: str = '/assets/',
86
assets_ignore: str = '',
87
external_scripts: List[Union[str, Dict]] = None,
88
external_stylesheets: List[Union[str, Dict]] = None,
89
suppress_callback_exceptions: bool = None,
90
prevent_initial_callbacks: bool = None,
91
show_undo_redo: bool = False,
92
plugins: List = None,
93
title: str = 'Dash',
94
update_title: str = 'Updating...',
95
**kwargs
96
): ...
97
98
def run(self, debug: bool = None, port: int = 8050, host: str = '127.0.0.1', **kwargs): ...
99
def callback(self, *args, **kwargs): ...
100
def clientside_callback(self, clientside_function, output, inputs, state=None, **kwargs): ...
101
```
102
103
[Core Application](./core-application.md)
104
105
### Callback System
106
107
Reactive programming system that connects user interactions to data updates through Input/Output dependencies and callback functions.
108
109
```python { .api }
110
class Input:
111
def __init__(self, component_id: Union[str, Dict], component_property: str): ...
112
113
class Output:
114
def __init__(self, component_id: Union[str, Dict], component_property: str): ...
115
116
class State:
117
def __init__(self, component_id: Union[str, Dict], component_property: str): ...
118
119
class ClientsideFunction:
120
def __init__(self, namespace: str, function_name: str): ...
121
122
def callback(*args, **kwargs): ...
123
def clientside_callback(clientside_function, output, inputs, state=None, **kwargs): ...
124
125
# Wildcard patterns
126
MATCH: Any # Match any ID in pattern-matching callbacks
127
ALL: Any # Match all IDs in pattern-matching callbacks
128
ALLSMALLER: Any # Match all smaller indices in pattern-matching callbacks
129
```
130
131
[Callback System](./callback-system.md)
132
133
### Component Libraries
134
135
Comprehensive component ecosystem including core components (dcc), HTML elements (html), and data tables (dash_table).
136
137
```python { .api }
138
# Dash Core Components (dcc)
139
class Graph(Component): ...
140
class Dropdown(Component): ...
141
class Slider(Component): ...
142
class Input(Component): ...
143
class Store(Component): ...
144
class Location(Component): ...
145
class Link(Component): ...
146
147
# Dash HTML Components (html)
148
class Div(Component): ...
149
class H1(Component): ...
150
class Button(Component): ...
151
class A(Component): ...
152
class P(Component): ...
153
154
# Dash DataTable
155
class DataTable(Component): ...
156
```
157
158
[Component Libraries](./component-libraries.md)
159
160
### Multi-Page Applications
161
162
Built-in support for single-page application (SPA) navigation with automatic routing, page registration, and SEO optimization.
163
164
```python { .api }
165
def register_page(
166
module: str = None,
167
path: str = None,
168
path_template: str = None,
169
name: str = None,
170
order: Union[int, float] = None,
171
title: str = None,
172
description: str = None,
173
image: str = None,
174
redirect_from: List[str] = None,
175
layout: Any = None,
176
**kwargs
177
): ...
178
179
page_registry: Dict[str, Any] # Registry of all registered pages
180
page_container: Component # Container component for page content
181
```
182
183
[Multi-Page Applications](./multi-page-apps.md)
184
185
### Special Values and Control
186
187
Special values and utilities for controlling callback execution and component updates.
188
189
```python { .api }
190
class NoUpdate:
191
"""Sentinel value to prevent component updates."""
192
pass
193
194
no_update: NoUpdate # Alias for NoUpdate()
195
196
class PreventUpdate(Exception):
197
"""Exception to prevent callback execution."""
198
pass
199
200
class Patch:
201
"""Partial updates for lists and dictionaries."""
202
def append(self, item): ...
203
def prepend(self, item): ...
204
def insert(self, index: int, item): ...
205
def remove(self, item): ...
206
def clear(self): ...
207
```
208
209
[Special Values and Control](./special-values.md)
210
211
### Background Callbacks
212
213
Asynchronous callback processing for long-running operations with progress reporting and caching support.
214
215
```python { .api }
216
class CeleryManager:
217
def __init__(self, celery_app): ...
218
219
class DiskcacheManager:
220
def __init__(self, cache_by: str = "session", cache: Any = None): ...
221
222
# Background callback decorator
223
@callback(
224
background=True,
225
manager=CeleryManager(celery_app),
226
running=[(Output("loading", "children"), "Running...")],
227
progress=[Output("progress", "value"), Output("progress", "max")],
228
progress_default=[0, 100]
229
)
230
def long_running_callback(*args): ...
231
```
232
233
[Background Callbacks](./background-callbacks.md)
234
235
### Asset Management
236
237
Static asset handling including CSS, JavaScript, images, and external resources with hot reloading and fingerprinting.
238
239
```python { .api }
240
def get_asset_url(path: str) -> str:
241
"""Get URL for asset file."""
242
...
243
244
def get_relative_path(path: str) -> str:
245
"""Get relative path from request."""
246
...
247
248
def strip_relative_path(path: str) -> str:
249
"""Strip relative path prefix."""
250
...
251
```
252
253
[Asset Management](./asset-management.md)
254
255
## Types
256
257
```python { .api }
258
# Core types
259
Component = Any # Base component class
260
ComponentIdType = Union[str, Dict, Component] # Component identifier
261
LayoutType = Union[Component, List, Dict, str, int, float] # Layout content
262
263
# Callback types
264
CallbackContext = Any # Callback execution context
265
CallbackFunction = Callable[..., Any] # Callback function signature
266
DependencyList = List[Union[Input, Output, State]] # Callback dependencies
267
268
# App configuration
269
ServerType = Any # Flask server instance
270
AssetList = List[Union[str, Dict[str, str]]] # External assets
271
PluginList = List[Any] # Plugin instances
272
273
# Multi-page types
274
PageConfig = Dict[str, Any] # Page configuration
275
PageRegistry = Dict[str, PageConfig] # Page registry
276
```