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

Update the properties of a range Slider

I’m trying to update the min and max values of a Dash Slider, like so (in this example, the min value) :

app.layout = html.Div([
    html.H1("NpyViewer"),
    html.Img(src="/display_feed"),
    html.Button("Change direction", id="change_button"),
    html.Div(
        [
            html.Label('Vmin/Vmax slider', id='minmax-range-label'),
            dcc.RangeSlider(
                id='minmax_slider',
                min=0,
                max=1,
                step=0.001,
                value=[0, 1]
            ),
        ],
        style={'margin-top': '20'}
    ),
])

@app.callback(
    dash.dependencies.Output("loaded-label", "children"),
    dash.dependencies.Output("minmax_slider", "min"),
    [dash.dependencies.Input("upload-data", "filename"), dash.dependencies.Input("upload-data", "contents")],
)
def _load_file(uploaded_filenames, uploaded_file_contents):
    """Save uploaded file and send a prompt."""

    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)

        return f"Loaded file : {name}", [0.2, 0.8]

    return "No file loaded", [0, 1]

But it raises : dash.exceptions.IncorrectTypeException: The input argument minmax_slider.minmust be a list or tuple ofdash.dependencies.Inputs.

I’m trying to update a label as well in the meantime, i don’t know if it interferes with it.

I feel like I’m missing something. Sorry, I’m still new to Plotly Dash !

Thanks

When having more that one Output, the format is just like it is for Input: Notice the [ ] I added around your Outputs

@app.callback(
    [dash.dependencies.Output("loaded-label", "children"),
    dash.dependencies.Output("minmax_slider", "min")],
    [dash.dependencies.Input("upload-data", "filename"), 
    dash.dependencies.Input("upload-data", "contents")],
)
1 Like