Last active
September 22, 2017 04:34
-
-
Save nkrumm/646b37211c7d21e82fea71beb8932d8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dash | |
import dash_html_components as html | |
import dash_core_components as dcc | |
from dash.dependencies import Input, Output, State, Event | |
app = dash.Dash() | |
app.config.supress_callback_exceptions=True | |
app.layout = html.Div([ | |
dcc.Location(id='url', refresh=False), | |
dcc.Link('Go to Cities', href='/cities'), | |
html.Br(), | |
dcc.Link('Go To Oceans', href='/oceans'), | |
html.Br(),html.Br(), | |
html.Div(id='page-content')]) | |
@app.callback(Output('page-content', 'children'),[Input('url', 'pathname')]) | |
def generate_layout(url): | |
if url == '/cities': | |
return html.Div([ | |
html.Label('Multi-Select Dropdown - Cities'), | |
dcc.Dropdown( | |
options=[ | |
{'label': 'New York City', 'value': 'NYC'}, | |
{'label': u'Montréal', 'value': 'MTL'}, | |
{'label': 'San Francisco', 'value': 'SF'} | |
], | |
multi=True, | |
id='input_cities' | |
), | |
html.Div(id='output_cities') | |
]) | |
elif url == '/oceans': | |
return html.Div([ | |
html.Label('Multi-Select Dropdown - Oceans'), | |
html.Div(children=[dcc.Dropdown( | |
options=[ | |
{'label': 'Pacific Ocean', 'value': 'pacific'}, | |
{'label': 'Atlantic Ocean', 'value': 'atlantic'}, | |
{'label': 'Indian Ocean', 'value': 'indian'} | |
], | |
multi=True, | |
id='input_oceans' | |
)]), | |
html.Div(id='output_oceans') | |
]) | |
else: | |
return "404" | |
@app.callback(Output('output_cities', 'children'), [Input('input_cities', 'value')]) | |
def display_output(value): | |
return 'You have selected the city "{}"'.format(value) | |
@app.callback(Output('output_oceans', 'children'), [Input('input_oceans', 'value')]) | |
def display_output(value): | |
return 'You have selected the ocean "{}"'.format(value) | |
if __name__ == '__main__': | |
app.run_server(debug=True, host='0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment