Practice
1
2
3import dash
4import dash_core_components as dcc
5import dash_html_components as html
6import plotly.graph_objs as go
1
2
3external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
4app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
5app.layout = html.Div(children=[
6
7])
1
2html.H1(children = 'Header'),
1
2
3dcc.Graph(
4 figure = {
5 'data': [
6
7 ],
8 'layout':
9 },
10 id = 'graph_id'
11 ),
1
2
3go.Table(header = {'values': ['<b>Year</b>',
4 '<b>Country</b>',
5 '<b>% of urban population</b>'],
6 'fill_color': 'lightgrey',
7 'align': 'center'},
8 cells = {'values': table.T.values})
1
2dcc.DatePickerRange(
3 start_date = urbanization['Year'].dt.date.min(),
4 end_date = urbanization['Year'].dt.date.max(),
5 display_format = 'YYYY',
6 id = 'dt_selector',
7),
1
2
3dcc.Checklist( options = [{'label': 'Africa', 'value': 'afr'},
4 {'label': 'Eurasia', 'value': 'eur'},
5 {'label': 'Australia', 'value': 'au'},
6 {'label': 'Americas', 'value': 'am'}],
7
8
9 value = ['afr', 'eur', 'au', 'am'],
10 id = 'continent_selector' )
1
2
3dcc.Dropdown( options = [{'label': 'Africa', 'value': 'afr'},
4 {'label': 'Eurasia', 'value': 'eur'},
5 {'label': 'Australia', 'value': 'au'},
6 {'label': 'Americas', 'value': 'am'}],
7
8
9 value = ['afr', 'eur', 'au', 'am'],
10 multi = True,
11 id = 'continent_selector')
1
2
3dcc.RadioItems(options = [{'label': 'Dog', 'value': 'dog',
4 {'label': 'Cat', 'value': 'cat'},
5 {'label': 'Opossum', 'value': 'possum'},
6 ],
7
8
9 value = 'possum',
10 id = 'pet_selector')
1
2@app.callback(
3 [Output('trig_func', 'figure'),
4 ],
5 [Input('mode_selector', 'value'),
6 ])
7def update_figures(selected_mode):
8
1
2
3@app.callback(
4 [Output('plot_1', 'figure'),
5 Output('plot_2', 'figure')
6 ],
7 [Input('control_1', 'value'),
8 Input('control_2', 'value'),
9 Input('control_3', 'value')
10 ])
11def update_figures(control_1_value, control_2_value, control_3_value):
12
13return (
14 {
15 'data': plot_1_data,
16 'layout': go.Layout(…)
17 },
18 {
19 'data': plot_2_data,
20 'layout': go.Layout(…)
21 },
22 )
1
2
3html.Div([
4 html.Div([
5 html.Label('I use 9 out of 12 available columns:'),
6 ], className = 'nine columns'),
7 html.Div([
8 html.Label('I use 3 out of 12 available columns:'),
9 ], className = 'three columns'),
10], className = 'row'),
1
2
3dcc.Graph(
4 style = {'height': '25vw'},
5 id = 'sales_by_platform'
6)
1
2
3html.Br()