I notice that ctx.inputs_list
is a bit greedy with what it captures. For instance, I have a callback below in which I want to capture just the value
prop in one list, and the relayoutData
in the other, but instead, I get all components and have to filter out the ones that don’t apply.
The filtering stage only adds two extra lines/per component, but it is rather inefficient as it requires me to iterate through every pattern matched component. Would it be possible to have this already filtered out before being put into the inputs_list?
Do you see any value add in having it unfiltered to begin with?
@app.callback(
Output('state', 'data'),
[
Input({'module': ALL, 'id': ALL}, 'value'),
Input({'module': ALL, 'submodule': ALL, 'id': ALL}, 'value'),
Input({'module': ALL, 'submodule': ALL, 'id': ALL}, 'relayoutData'),
],
[State('state', 'data')],
)
def update_state(*args):
module_values, submodule_values, graph_relayouts = ctx.inputs_list
module_values = [i for i in module_values if 'value' in i]
if module_values:
for value in module_values:
handle_value(value, prev)
submodule_values = [i for i in submodule_values if 'value' in i]
if submodule_values:
for value in submodule_values:
handle_value(value, prev)
graph_relayouts = [i for i in graph_relayouts if 'value' in i]
if graph_relayouts:
for relayout in graph_relayouts:
handle_relayout(relayout, prev)