@nedned thanks for the continued pointers. Going to take baby steps here
Here’s my modified attempt, but I still get nothing until the slider is at 5… now I’m thinking the slider id has to exist in the layout, not just in the list for the callback to succeed. Is that corect?
import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
import json
app = dash.Dash()
app.css.append_css({'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css'})
app.config['suppress_callback_exceptions']=True
input_list = [dcc.Slider(id='slider_{}'.format(n),
min=1, max=5, step=1, value=1,
marks={i: i for i in range(1, 6)}) for n in range(1, 6)]
app.layout = html.Div([
html.Div([
html.Label('number of inputs'),
dcc.Slider(id='n_sliders', min=1, max=5, step=1, value=1,
marks={i: i for i in range(1, 6)}),
html.Br(),
html.Hr(),
html.Div(id='input_container')],
style={'float': 'left', 'width': '20%',
'padding': '0 0 50px 5px'}),
html.Div([
html.Div(id='slider_values')],
style={'float': 'right', 'width': '75%'})
])
@app.callback(
Output('input_container', 'children'),
[Input('n_sliders', 'value')])
def make_sliders(n):
print(n)
return [html.Div(slider,
style={'padding': '0 0 20px'}) for slider in input_list[0:n]]
@app.callback(
Output('slider_values', 'children'),
[Input('slider_{}'.format(i), 'value') for i in range(1, 6)],
[State('n_sliders', 'value')])
def printcontents(i1, i2, i3, i4, i5, n):
vals = [i1, i2, i3, i4, i5][0:n]
print(vals)
return ', '.join(str(val) for val in vals)
if __name__ == '__main__':
app.run_server(debug=True)
I’m assuming this from this piece of code I forgot, then re-remembered, and still haven’t entirely wrapped my head around from the dynamic example we’ve been discussing:
# create a callback for all possible combinations of dynamic controls
# each unique dynamic control pairing is linked to a dynamic output component
for value1, value2 in itertools.product(
[o['value'] for o in app.layout['datasource-1'].options],
[o['value'] for o in app.layout['datasource-2'].options]):
app.callback(
Output(generate_output_id(value1, value2), 'children'),
[Input(generate_control_id(value1), 'value'),
Input(generate_control_id(value2), 'value')])(
generate_output_callback(value1, value2)
)
For my example, what’s the translation here? I need callbacks for 1 slider, 2 sliders, … 5 sliders that are all separately? Or my first callback where I return the [0:n] slice of my input_list should also generate a tailored callback based on how many exist?
Once I get this, then I’ll try and understand what you’re saying about all combinations of plan and slider!