How to generate a variable number of sliders

Lets say I have a function like this:

def generate_sliders(df):
    sliders = []
    parameter_columns = [x for x in df.columns if 'mse' not in x]
    for x in parameter_columns:
        min_value = df_initial[x].min()
        max_value = df_initial[x].max()
        values = df_initial[x].unique()
        sliders.append(dcc.Slider(min_value, max_value, step=None, marks={x:x for x in values}, value=min_value, id=x))
    return sliders

How can I it use to create a variable number of sliders in my Dash App:

app1 = html.Div([
    sidebar,
    html.Div([
        dcc.Dropdown(experiments),
        dcc.Dropdown(summary),
        # sliders here
    ],
        style=style
    )
])

Also, I have a callback the needs to to take the value of all sliders as input.

Thank you very much for your help :slight_smile:

Hi @HansPeter123 you could just add the list of components to the html.Div() children list:

import dash
from dash import html

list_of_comps = [html.Button(f'b{i}', id=f'b{i}') for i in range(3, 8)]

app = dash.Dash()
app.layout = html.Div(
    [
        html.Button('b1', id="b1"),
        html.Button('b2', id="b2"),
    ] + list_of_comps
)

if __name__ == "__main__":
    app.run(debug=True)

Concerning the callback you might look into this:

1 Like

Cool thank you, I will check the pattern-matching callbacks.