I created an Dash app with 2 heatmaps where it recomputes the value every second. I also have a checkbox core component at the top where it filters for which values to get heatmap for.
The issue is the checkbox defaults back to its default values whenever the graph updates.
Another issue is after a while, the graph doesn’t update anymore and the top of the browser still says “Updating…”
@chriddyp - Here is a simple example of the issue i’m facing. The dropdown selection defaults back to ‘Choice 1’ after every interval.
import dash
import dash_core_components as dcc
from dash.dependencies import Input, Output, State
import dash_html_components as html
app = dash.Dash(__name__)
server = app.server
app.layout = html.Div([
dcc.Dropdown(
id = 'variable_selected',
options = [{'label':'Choice 1','value':1},
{'label':'Choice 2','value':2},
{'label':'Choice 3','value':3}],
value=1
), ## this will default to 1 after every interval
dcc.Interval(id='update_interval', interval=2000, n_intervals=0),
html.Div(id='output_example')
])
@app.callback(Output('output_example', 'children'), [Input('update_interval', 'n_intervals')])
def test(interval):
return "The interval number is {}".format(interval)
if __name__ == '__main__':
app.run_server(debug=True,port=8055)
OK, I see what the problem is. The component isn’t keeping its own state after the app gets refreshed.
Now, this particular case is uncommon because the dcc.Dropdown isn’t hooked up to any callback. If it was hooked up to a callback, you wouldn’t see the issue (after it is hooked up to a callback, Dash’s front-end maintains the components state, rather than the component itself. This means that when dash’s front-end rerenders the app, it will supply the correct value).
So for now, just connect all of your components. If you change your callback to be:
@app.callback(
Output('output_example', 'children'),
[Input('update_interval', 'n_intervals'),
Input('variable_selected', 'value')])
def test(interval, value):
return "The interval number is {} and the value is {}".format(
interval, value
)