Hello I have a simple Dash app with a slider component
dcc.Slider(
id='temp-slider',
min=18,
max=25,
step=0.5,
value=DEFAULT_TEMP,
marks={i: '{}°C'.format(i) for i in range(18, 26)},
persistence=True
),
and a callback that writes the current slider position to a file which is read by a backend
@app.callback(Output('temp-slider', 'value'),
[Input('temp-slider', 'value')])
def update_slider(value):
json.dump({'setpoint': value}, open('setpoint.json', 'w'))
return value
The problem is whenever I open a new instance (e.g. new tab) to my server the slider will reinitialize to DEFAULT_TEMP
.
Can anyone suggest a simple fix to have the slider value set from the file on the app launch for every user?
Thanks