James
James

Reputation: 11

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

Upvotes: 1

Views: 2063

Answers (1)

Adam Schroeder
Adam Schroeder

Reputation: 768

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

Upvotes: 2

Related Questions