简体   繁体   中英

Can I use multiple inputs to my dash plotly callback, but only have one trigger the callback?

Is it possible to use multiple inputs to my dash plotly callback, but only have one trigger the callback? It doesn't seem so.

I want to trigger the callback only when a button is pressed. I don't know how to get the other data I need within the callback function if I don't pass it as one of the inputs.

This runs if I "get_file" changes, even if "Button" is not clicked

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

This doesn't work because I need the filename and content within the function

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

welcome to Dash. Try putting your git_files into a State argument instead of Input, like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM