【问题标题】:Dash - how to get callback to autorefresh with no button click?破折号 - 如何在不单击按钮的情况下获得自动刷新的回调?
【发布时间】:2021-11-11 14:45:52
【问题描述】:

我在破折号回调中有一些输入表单,可将​​输入转换为文本摘要。

现在,我必须单击一个按钮来刷新该文本摘要,但我希望刷新是自动的 - 每当用户在输入框中编辑值时。

我尝试将State 变量更改为Input 并删除回调输入中对按钮的引用,但这并没有帮助 - 我仍然需要点击按钮以刷新文本。

有没有办法让文本摘要在用户更改输入框时自动刷新?

@app.callback(
    Output('desc', 'children'),
    Input('submit-button-choose-event', 'n_clicks'),
    State("full-input-boxes", "children"),
             )
def refresh_desc(n_clicks,children):
    txt = ''
    if children:
        inputs = [i["props"] for i in children["props"]["children"] if i["type"] == "Input"]
        #process the inputs into txt
    return txt

【问题讨论】:

    标签: python plotly-dash


    【解决方案1】:

    将状态更改为输入是要走的路,你需要组件的输入value

        @app.callback(
            Output('desc', 'children'),
            Input('full-input-boxes', 'value'))
        def refresh_desc(txt):
            # ...
            return txt
    

    这适用于以下输入类型:textnumberpasswordemailsearch

    【讨论】:

    • 谢谢@ericlavault。奇怪的是,这不起作用——当我第一次加载页面时它会刷新,但当我改变输入时它不会改变。我正在使用“儿童”框,因为我的输入是动态的,取决于另一个回调,所以很遗憾,我无法对每个输入框进行硬编码
    • 好的,将代码(定义组件和涉及的回调)放入您的问题中,以便我们进一步调查。
    猜你喜欢
    • 1970-01-01
    • 2019-06-09
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多