In the next code ( is an example), callback is called twice in every single event.
(在下一个代码中(作为示例),在每个单个事件中,回调都会被调用两次。)
when you show the slider's id the last id will be repeated in every short time period. (当您显示滑块的ID时,最后的ID将在每个较短的时间段内重复。)
Why? (为什么?)
how i can fix it? (我该如何解决?)
CODE:
(码:)
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
html.Div([
dcc.Slider(
id='{}'.format(i),
min=0,
max=20,
step=0.5,
value=10,
) for i in range(10)]),
html.Div(id='slider-output-container')
])
def generate_inputs():
return [Input('{}'.format(_),'value') for _ in range(10)]
@app.callback(
dash.dependencies.Output('slider-output-container', 'children'),
generate_inputs()
)
def update_output(*values):
ctx = dash.callback_context
id = ctx.triggered[0]['prop_id'].split('.')[0]
print(id)
return 'You have selected "{}"'.format(values[0])
if __name__ == '__main__':
app.run_server()
ask by José Marqueses Saxo translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…