Dash Basics: App Layout with Components
You'll learn how to structure a Dash application using HTML and core components to build interactive data science dashboards.
What is Dash?
Dash is a Python framework for building web-based data applications. Think of it like building with LEGO blocks: you snap together different components (graphs, dropdowns, sliders, text) to create an interactive dashboard without writing HTML, CSS, or JavaScript directly.
Core Building Blocks
A Dash app has two main types of components:
HTML Components
These structure your page layout like a website:
html.Div()– containers that hold other elementshtml.H1(),html.H2()– headingshtml.P()– paragraphs of text
Core Components
These add interactivity and visualizations:
dcc.Graph()– displays Plotly chartsdcc.Dropdown()– selection menusdcc.Slider()– sliding value selectorsdcc.Input()– text input fields
Basic Layout Structure
import dash
from dash import dcc, html
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1("My Data Dashboard"),
html.P("Explore the data interactively"),
dcc.Dropdown(
id='my-dropdown',
options=[{'label': 'Option A', 'value': 'A'}]
),
dcc.Graph(id='my-graph')
])
Components are nested inside containers (like html.Div) using Python lists. The app.layout defines everything users see.
The Analogy
Think of Dash like arranging furniture in a room. The html.Div is the room itself, headings and text are decorative elements, and interactive components (graphs, dropdowns) are functional furniture users interact with.
Key Takeaway: Dash apps combine HTML components for structure and core components for interactivity, all defined in a nested Python layout that requires no direct web development knowledge.