【问题标题】:Can I use multiple inputs to my dash plotly callback, but only have one trigger the callback?我可以在破折号情节回调中使用多个输入,但只有一个触发回调吗?
【发布时间】:2022-01-17 20:39:03
【问题描述】:

是否可以对我的破折号情节回调使用多个输入,但只有一个触发回调?好像不是这样的。

我只想在按下按钮时触发回调。如果我不将它作为输入之一传递,我不知道如何在回调函数中获取我需要的其他数据。

如果我“get_file”发生变化,即使“按钮”没有被点击,这也会运行

@app.callback(
    Output("file_to_upload", "children"),
    [Input("Button", "n_clicks"),
     Input("get_file", "filename"), 
     Input("get_file", "contents")]
)
def get_query_file(n_clicks, uploaded_filenames, uploaded_file_contents):

这不起作用,因为我需要函数中的文件名和内容

@app.callback(
    Output("file_to_upload", "children"),
    [Input("Button", "n_clicks")]
)
def get_query_file(n_clicks):

【问题讨论】:

    标签: python callback plotly plotly-dash


    【解决方案1】:

    欢迎来到 Dash。 尝试将您的 git_files 放入 State 参数而不是 Input,如下所示:

    @app.callback(
    Output("file_to_upload", "children"),
    Input("Button", "n_clicks"),
    [State("get_file", "filename"), 
    State("get_file", "contents")]
    )
    def get_query_file(n_clicks, uploaded_filenames, uploaded_file_contents):
    

    【讨论】:

    • 请注意,States 会获取信息,但不会像 Input 那样触发回调。
    • 谢谢,有帮助。
    猜你喜欢
    • 2021-05-01
    • 2019-06-09
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    相关资源
    最近更新 更多