我是新来的,我需要一些帮助。我需要创建一个动态数量的输入,但我不知道如何为每个滑块组件绑定动态数量的回调。我只能创建动态数量的滑块,但正如您在代码中看到的,我需要硬编码回调的数量。有没有更好的方法可以让它更具活力?在
@app.callback(
Output('slider-container', 'children'),
[Input('button', 'n_clicks')])
def add_sliders(n_clicks):
return \
html.Div([
html.Div([
html.Div(dcc.Slider(id='slider-{}'.format(i))),
dcc.Input(
id='input-{}'.format(i),
placeholder='Graph Name',
type='text',
value=''
),
html.Div(id='output-{}'.format(i), style={'marginTop': 30})
]) for i in range(n_clicks)]
)
# up to 10 sliders
for i in range(10):
@app.callback(
Output('slider-{}'.format(i), 'children'),
[Input('slider-{}'.format(i), 'value'),
Input('input-{}'.format(i), 'value')])
def update_output(slider_i_value, input_i_value):
return str(slider_i_value) + str(input_i_value)
目前没有回答
相关问题 更多 >
编程相关推荐