Created
March 5, 2020 16:14
-
-
Save randyzwitch/69881ac0f555c74654e5b598701e462b to your computer and use it in GitHub Desktop.
Callback example in Dash
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
#### THIS IS A SUMMARY, THIS FILE WILL NOT RUN AS-IS #### | |
#### INPUTS to build_telemetry_chart #### | |
#https://github.com/omnisci/F1-demo/blob/726c56ba4e8c878abeef81b7cf680bd4d36a4bd2/f1dash/controls.py#L9-L32 | |
#### reference lap: build list dynamically with callback | |
reflapmenu = dcc.Dropdown( | |
id='reflapmenu', | |
searchable=False, | |
clearable=False, | |
style=dict(minWidth = '250px', paddingRight = '15px', borderRadius = 0) | |
) | |
#### telemetry metrics: these are the reasonable values from the table | |
metricmenu = dcc.Dropdown( | |
id='metricmenu', | |
options=[ | |
{'label': 'speed', 'value': 'speed'}, | |
{'label': 'enginerpm', 'value': 'enginerpm'}, | |
{'label': 'brake', 'value': 'brake'}, | |
{'label': 'gear', 'value': 'gear'}, | |
{'label': 'steer', 'value': 'steer'}, | |
{'label': 'throttle', 'value': 'throttle'} | |
], | |
value="speed", | |
searchable=False, | |
clearable=False, | |
style=dict(minWidth = '250px', paddingRight = '15px', borderRadius = 0, color="#FFFFFF") | |
) | |
#### Listens for the 'value' field of 'reflapmenu' and 'value' field of 'metricmenu' to change | |
#### Runs build_telemetry_chart function, which sends its output to 'telemetry-graph' id | |
#https://github.com/omnisci/F1-demo/blob/726c56ba4e8c878abeef81b7cf680bd4d36a4bd2/f1dash/app.py#L182-L185 | |
#callback decorator | |
@app.callback(Output('telemetry-graph', 'figure'), | |
[Input('track-interval', 'n_intervals'), Input('reflapmenu', 'value'), Input('metricmenu', 'value')]) | |
def build_telemetry_chart(notused, reflapvalue, metric): | |
... | |
#### This code has 'telemetry-graph' as its id, so the results of build_telemetry_chart modifies the 'figure' field of 'telgraph' | |
#https://github.com/omnisci/F1-demo/blob/726c56ba4e8c878abeef81b7cf680bd4d36a4bd2/f1dash/telemetry.py#L31-L35 | |
telgraph = dcc.Graph(id='telemetry-graph', | |
config={ | |
'displayModeBar': True | |
} | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment