Quick Reference · reactive web apps in pure Python

dash cheat sheet

Dash turns Python into interactive web apps — no JavaScript required. Two ideas carry the whole framework: layout (app.layout, a tree of components that describes what the app looks like) and callbacks (@callback functions that describe how it reacts). Wire them with three dependency objects — an Input triggers a callback, an Output receives its return value, a State is read without triggering — and Dash keeps the browser and your Python in sync automatically.

setup / app layout · html components · dcc callbacks advanced callbacks state · pages · deploy gotcha most common

Distilled & cross-checked across: dash.plotly.com · Fundamentals (layout · callbacks · graphing) · dcc & html reference · pattern-matching · background callbacks · Dash 3.0 / 4.x migration · Dash in 20 Minutes

The reactive loop — layout describes it, callbacks react to it
CLIENT · the browser SERVER · your Python app.layout a tree of components html.Div([ … ]) dcc.Dropdown(id="ctrl") an input control — its value changes dcc.Graph(id="out") an output target — its figure updates dcc.Store(id="store") holds data read as State @callback @callback( Output("out", "figure"), Input("ctrl", "value"), State("store", "data"), ) def update(value, data): return figure pure Python — runs on the server re-runs whenever an Input changes triggers read-only returns → updates the Output property the three wirings Output sets a property Input triggers + passes value State passed, doesn't trigger every component property is reactive (Input or Output) ctx.triggered_id → which input fired app.layout = what it looks like · @callback = how it reacts Dash keeps component properties in sync between the browser and your Python — reactively, with no JavaScript required
01Setup & Appthe boilerplate
02Layout · HTMLdash.html · the tags
03Layout · stylenesting & CSS
04Core Componentsdash.dcc · controls
05dcc · data & utilitythe invisible helpers
06The @callbackwhat makes it react ★
07Multiple I/O & Statewiring it up
08Context & controlctx · skip · duplicate
09Interactive graphingdcc.Graph as an Input
10Pattern-matchingdynamic components
11Patch & clientsidefast partial updates
12Background callbackslong-running work
13Multi-page appsuse_pages
14Share data & deploystate · production
15The reactive modelthe one big idea ★
16Gotchasthe usual traps

Four ideas worth a picture

The loop up top shows the whole cycle. These four zoom in on the pieces that trip people up: how the layout maps to the page, how a callback's parts line up, why Input and State differ, and how pattern-matching scales to dynamic UIs.

the layout is a tree

Components nest like HTML. Dash renders the tree to the DOM; each id becomes a handle callbacks can target.

app.layout html.Div html.H1("Dashboard") dcc.Dropdown(id="ctrl") dcc.Graph(id="out") renders Dashboard ▾ dropdown the browser DOM

how a callback lines up

Decorator order is the contract: Inputs then States become the function's args, in order; the return feeds the Output(s).

@callback( Output("out","figure") Input("ctrl","value") State("store","data") ) def update( value data ): return figure inputs → args return → output order matters: inputs, then states

Input triggers, State just reads

Both values reach your function — but only an Input change starts the callback. Use State for "read this when the button fires".

Input changes → FIRES ✓ callback runs State changes → nothing ✗ (idle) its value is still read when the callback runs Button.n_clicks = Input · Textbox.value = State

MATCH vs ALL for dynamic UIs

Dict ids let one callback serve components created at runtime. MATCH handles them one at a time; ALL gathers them together.

id = {"type":"filter", "index": i} index 0 index 1 index 2 MATCH fires for index 1 one at a time ALL [v0, v1, v2] as a list all together

Worth memorizing

layout + callbacksa component tree + reactive Python functions
Input · Output · Statetriggers · receives return · read-only
every property is reactiveany prop can be an Input or an Output
match the idscallback ids must exist in app.layout
@callback placementdirectly above the def — no blank line
no_update / PreventUpdateskip one output · abort the callback
ctx.triggered_idwhich input fired (esp. with dict ids)
MATCH · ALLdict-id wildcards for dynamic components
dcc.Storeshare data between callbacks — never globals
app.run · app.serverdebug=True to dev · gunicorn app:server to ship