I am working on a simple dash application. I need the dcc intervals
to keep refreshing my application for a task. however, whenever the user changes an input I will like the n from the intervals to start from 1 again instead of the last n.
Here is a snippet of my code
import dash
from dash_core_components.Interval import Interval
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Output, Input, State
# This stylesheet makes the buttons and table pretty.
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Interval(id='interval-test', interval=2000),
dcc.Dropdown(
id='demo-dropdown',
options=[
{'label': 'New York City', 'value': 'NYC'},
{'label': 'Montreal', 'value': 'MTL'},
{'label': 'San Francisco', 'value': 'SF'}
],
value='NYC'
),
html.H1(id='test-output')
])
@app.callback(Output('test-output', 'children'),
State('interval-test', 'n_intervals'), Input('demo-dropdown', 'value'),)
def interval_update(n, val):
ctx = dash.callback_context
if not ctx.triggered:
print(n)
else:
return n
if __name__ == '__main__':
app.run_server(debug=True)