每当输入有一些触发时,如何使破折号间隔从 0 开始

How to make dash interval start from 0 anytime there is some trigger from the input

我正在开发一个简单的破折号应用程序。我需要 dcc intervals 来不断刷新我的任务应用程序。但是,每当用户更改输入时,我希望间隔中的 n 再次从 1 而不是最后一个 n 开始。

这是我的代码片段

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)

设置回调以输出到 n_intervals 属性 并将其重置为 0。像这样:

@app.callback(Output('my-interval', 'n_intervals'),
              [Input('whatever', 'whatever'),
               # other inputs
              ])
def interval_update(input_1): # add other args for additional inputs
    return 0