Dash

4.1.0 · active · verified Thu Apr 09

Dash is a Python framework for building analytical web applications. Developed by Plotly, it allows users to create interactive dashboards and data visualization tools entirely in Python, without requiring JavaScript or web development expertise. It is currently at version 4.1.0 and typically releases minor versions and release candidates regularly, leading up to major version updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic Dash application with a single button and a division that updates its text when the button is clicked. It uses modern Dash imports and the `@callback` decorator, including `prevent_initial_call` to avoid errors on initial page load.

import os
from dash import Dash, html, dcc, Input, Output, State, callback

# Initialize the Dash app
# For deployment, consider setting up a robust WSGI server (e.g., Gunicorn)
# and handling config via environment variables.
app = Dash(__name__)

app.layout = html.Div([
    html.H1("Dash Quickstart App"),
    html.Button("Click Me", id="my-button", n_clicks=0),
    html.Div(id="my-output", children="No clicks yet.")
])

# Define a callback to update the output based on button clicks
@callback(
    Output("my-output", "children"),
    Input("my-button", "n_clicks"),
    State("my-output", "children"),
    prevent_initial_call=True # Prevents the callback from firing on initial load
)
def update_output(n_clicks, current_text):
    if n_clicks is None:
        # This branch might be reached if prevent_initial_call=False
        return "No clicks yet."
    return f"Button has been clicked {n_clicks} times!"

# Run the app
if __name__ == "__main__":
    # In production, set debug=False and use a production-ready WSGI server
    app.run_server(debug=True)

view raw JSON →