Black Lives Matter. Please consider donating to Black Girls Code today.

Callback : Multiple outputs, apply change to only some outputs


    [dash.dependencies.Output("loaded-label", "children"),
     dash.dependencies.Output("minmax_slider", "min"),
     dash.dependencies.Output("minmax_slider", "max")],
    [dash.dependencies.Input("upload-data", "filename"), dash.dependencies.Input("upload-data", "contents")],
def _load_file(uploaded_filenames, uploaded_file_contents):
    """Save uploaded file, send a prompt and updates components that need to be updated."""

    if uploaded_filenames is not None and uploaded_file_contents is not None:
        name = uploaded_filenames[0]
        data = uploaded_file_contents[0]

            ds.update_source(name, data)
        except Exception:
            return "Invalid file", None, None

        return f"Loaded file : {name}", -5, 5

    return "No file loaded", None, None

I have this code in a callback, loading a file and updating components to match that file’s attributes. However, when giving an invalid file, I’d like to update a label but do no changes to the other components. That’s what I tried with None, however, None will reset my Slider minmax_slider's min and max values to 0, when I want to left them as they are.

I could raise an exception, but then I wouldn’t be able to update the label to say “Invalid file” or “No file loaded”.

Is there a way to achieve what I try to do ?

Thanks !

What you’re looking for is dash.no_update which is a special return value that says precisely this: do not update.
Raising the exception PreventUpdate does this at the complete callback level.

see this page


It was ! Thank you arty :slight_smile: