在下一个代码中(作为示例),在每个单个事件中,回调都会被调用两次。 当您显示滑块的ID时,最后的ID将在每个较短的时间段内重复。 为什么? 我该如何解决?

码:

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

本文未有回复,本站智能推荐:

关注微信公众号