Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当输入触发时,如何使破折号间隔从0开始_Python_Python 3.x_Plotly Dash_Plotly Python - Fatal编程技术网

Python 当输入触发时,如何使破折号间隔从0开始

Python 当输入触发时,如何使破折号间隔从0开始,python,python-3.x,plotly-dash,plotly-python,Python,Python 3.x,Plotly Dash,Plotly Python,我正在开发一个简单的dash应用程序。我需要dcc间隔来不断刷新我的应用程序以执行任务。但是,每当用户更改输入时,我希望间隔中的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

我正在开发一个简单的dash应用程序。我需要
dcc间隔
来不断刷新我的应用程序以执行任务。但是,每当用户更改输入时,我希望间隔中的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_interval
属性,并将其重置为0。大概是这样的:

@app.callback(输出('my-interval','n_interval'),
[输入('whatever','whatever'),
#其他投入
])
def间隔_更新(输入_1):#为其他输入添加其他参数
返回0