python - 在 Dash 框架中动态添加 HTML 输入

标签 python html python-2.7 dynamic plotly-dash

我是 Dash 的新手,我需要一些帮助。我需要创建动态数量的输入,但我不知道如何为每个 slider 组件绑定(bind)动态数量的回调。我只能创建动态数量的 slider ,但正如您在代码中看到的,我需要硬编码回调的数量。有没有更好的方法来让它更有活力?

@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)

最佳答案

从 Dash 1.11.0 开始,您拥有 Pattern Matching Callbacks就是这样做的。在您的情况下,您将使用带有 MATCH 的那个.

关于python - 在 Dash 框架中动态添加 HTML 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50961759/

相关文章:

python - 如何显示Series中某个索引的所有值?

python - 如何将 pymssql 死锁捕获为异常?

javascript - 如何让输入点击按钮

python - 查找所有使用 `print` 但不包含 `from __future__ import print_function` 的文件

python - 查找仅在第一个字典中出现的键值对

python - 在 python 中将原始位发送到终端

python - 如何在 Vim 中通过 ALE 运行 isort?

javascript - 警告用户他正在退出页面的最佳方式

html - 边距设置对于设置链接元素水平居中无效

python - python2.7 中的正则表达式