How to return multiple outputs while using pattern matching callback

Here’s a simplified snippet of what I’m trying to implement. How can I make a callback like this work?
Each div-container.children is a div which has 5 dropdowns each.
So basically, I want to return all 5 lists as options to 5 different dropdowns present in each child of div-container

@app.callback(
    [Output({'type': 'dropdown-1','index': ALL}, 'options'),
    Output({'type': 'dropdown-2','index': ALL}, 'options'),
    Output({'type': 'dropdown-3','index': ALL}, 'options'),
    Output({'type': 'dropdown-4','index': ALL}, 'options'),
    Output({'type': 'dropdown-5','index': ALL}, 'options')],
    Input('button', 'n_clicks'),
    State('div-container', 'children')
)
def create_dropdown_options(h5_file, children):
  # some code to prepare dropdown list.... list1, list2,....., list5
  output = [list1, list2, list3, list4, list5]
  return [output for i in range(len(children))]

For now I’m getting an like this:

dash._grouping.SchemaLengthValidationError: Schema: [<Output `{"index":["ALL"],"type":"group-filter"}.options`>, <Output `{"index":["ALL"],"type":"variable-filter"}.options`>, <Output `{"index":["ALL"],"type":"component-filter"}.options`>, <Output `{"index":["ALL"],"type":"t-signal-selector"}.options`>, <Output `{"index":["ALL"],"type":"group-filter-2"}.options`>, <Output `{"index":["ALL"],"type":"variable-filter-2"}.options`>, <Output `{"index":["ALL"],"type":"component-filter-2"}.options`>, <Output `{"index":["ALL"],"type":"n-signal-selector"}.options`>]
Path: ()
Expected length: 8
Received value of length 1:

Hi,

If I understand your code right, you have one of each Dropdown per child of div-container, right?

In this case, I believe you are looping over the number of children in the wrong list. I would imagine you want to return:

output = [list1, list2, list3, list4, list5]
return [[opt for i in range(len(children)] for opt in output]

So if children has 2 elements, this will return a list len=5 where each element is a list len 2, matching the number of callbacks per type. Or, in other words, each output should be a list with the same len as the number of matching components.

I haven’t tested to see if works, so please let me know if it does. Hope it helps! :smiley:

1 Like

Sorry for the confusion,
Each div-container.children is a div which has 5 dropdowns each.

So basically, I want to return all 5 lists as options to 5 different dropdowns present in each child of div-container

1 Like

Ok, it is clear now. Thanks!

Does my suggestion work?

yes, does exactly what I wanted it to. Thank you so much !

1 Like