Skip to content

Instantly share code, notes, and snippets.

@bpostlethwaite
Last active September 24, 2018 20:21
Show Gist options
  • Save bpostlethwaite/ee453ef317b2bdc45a8ded535daaedb1 to your computer and use it in GitHub Desktop.
Save bpostlethwaite/ee453ef317b2bdc45a8ded535daaedb1 to your computer and use it in GitHub Desktop.
possible solution for 2 input graph
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
DATA = [
{"value": "MTL", "label": "Montreal", "x": [1, 2, 3], "y": [4, 1, 2]},
{"value": "NYC", "label": "New York", "x": [1, 2, 3], "y": [2, 4, 5]},
{"value": "SF", "label": "San Fransisco", "x": [1, 2, 3], "y": [1, 8, 3]},
{"value": "HOU", "label": "Houston", "x": [1, 2, 3], "y": [3, 4, 12]},
]
app = dash.Dash(__name__)
server = app.server
app.layout = html.Div(
[
dcc.Input(id="my-input", value="initial value", type="text"),
dcc.Checklist(id="checklist",
options=DATA,
values=[DATA[0]["value"]]),
dcc.Graph(id="example-graph"),
], id="base"
)
@app.callback(
Output(component_id="example-graph", component_property="figure"),
[
Input(component_id="my-input", component_property="value"),
Input(component_id="checklist", component_property="values"),
],
)
def update_output_div(input_value, checked):
data = [make_bar(d) for d in DATA if d["value"] in checked]
return {"data": data, "layout": {"title": input_value}}
def make_bar(data_entry):
return {
"type": "bar",
"name": data_entry["label"],
"x": data_entry["x"],
"y": data_entry["y"],
}
if __name__ == "__main__":
app.run_server(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment