From 5587ac45f66f0eacfdd4daf862d38d85d9c9bc98 Mon Sep 17 00:00:00 2001 From: Konstantin Koslowski Date: Fri, 15 Nov 2019 11:52:48 +0100 Subject: [PATCH] homecontrol-dash: properly update max slider values in callback --- homecontrol-dash.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/homecontrol-dash.py b/homecontrol-dash.py index 15b5544..0aa6f09 100755 --- a/homecontrol-dash.py +++ b/homecontrol-dash.py @@ -57,7 +57,7 @@ app.layout = html.Div(children=[ dcc.Graph( id='graph-sensor-values', figure={ - 'data': [ {'x': [0], 'y': [0], 'mode': 'markers', 'name': 'None'} ], + 'data': [ {'x': [0], 'y': [0], 'mode': 'line', 'name': 'None'} ], 'layout': { 'title': 'initial values' } } ) @@ -115,26 +115,23 @@ def update_slider_limit(value): @app.callback( - [Output('slider-min-txt', 'children'), Output('slider-min', 'max')], + Output('slider-min-txt', 'children'), [Input('slider-min', 'value')]) def update_slider_min(value): - txt = "From: %s" % (time.strftime("%Y/%m/%d %H:%M", time.localtime(float(value))) if + return "From: %s" % (time.strftime("%Y/%m/%d %H:%M", time.localtime(float(value))) if value > 0 else 0) - t = time.time() - return txt, t @app.callback( - [Output('slider-max-txt', 'children'), Output('slider-max', 'max')], + Output('slider-max-txt', 'children'), [Input('slider-max', 'value')]) def update_slider_max(value): - txt = "To: %s" % (time.strftime("%Y/%m/%d %H:%M", time.localtime(float(value)))) - t = time.time() - return txt, t + return "To: %s" % (time.strftime("%Y/%m/%d %H:%M", time.localtime(float(value)))) @app.callback( - Output('graph-sensor-values', 'figure'), + [Output('graph-sensor-values', 'figure'), Output('slider-min', 'max'), + Output('slider-max', 'max')], [Input('tabs-select-sensor', 'value'), Input('slider-min', 'value'), Input('slider-max', 'value'), Input('slider-limit', 'value')]) def update_graph_sensor_values(sensorId, min_ts, max_ts, limit): @@ -149,9 +146,9 @@ def update_graph_sensor_values(sensorId, min_ts, max_ts, limit): x = [0] y = [0] return { - 'data': [ {'x': x, 'y': y, 'mode': 'markers', 'name': "%s" % (s)} ], + 'data': [ {'x': x, 'y': y, 'mode': 'line', 'name': "%s" % (s)} ], 'layout': { 'title': 'Data for sensor: %s (%d elements)' % (s, len(x)) } - } + }, time.time(), time.time() if __name__ == '__main__':