Building the Layout of Dash apps:
- The layout of a Dash app is defined using a hierarchical structure of components.
- These components appear in the order they are defined in the code, and they are nested according to how they are defined.
- For example, in the code snippet below, the H1 element is a child of the Div element, and the Div element is a child of the app layout. The H1 element will be rendered inside the Div element on the page.
- These components appear in the order they are defined in the code, and they are nested according to how they are defined.
python
1# ---Snippet---
2app.layout = html.Div([
3 html.H1('My Dashboard')
4 ])
5# ---Snippet---Dash HTML Components module:
- Contains components for every HTML tag, such as H1, H2, P, Div.
- Examples:
python
1# ---Snippet---
2# <h1>My Dashboard</h1>
3html.H1(children='My Dashboard'),
4
5# <div><h1>My Dashboard</h1></div>
6html.Div(children=html.H1(children='My Dashboard'))
7# ---Snippet---- The children parameter is the content that goes inside the HTML tag. It can be a string, a number, or even another component. When the app renders, the children content will be displayed inside the corresponding HTML tag on the page.
Dash Core Components module:
- Contains components that are interactive and can be manipulated by users, such as: dropdowns, checklists, Plotly graphs.
- Examples:
python
1# ---Snippet---
2 dcc.Dropdown(options=df['country'].unique(), value='default value'),
3 dcc.Graph(figure=line_fig),
4 dcc.Checklist(options=df['region'].unique()),
5 dcc.Graph(figure=bar_fig),
6# ---Snippet---