Hi there,
I have a question. The thing is, when I need to use pattern matching to match some components that are associated, they have some different properties, I have to write an additional trigger to handle it.
like:
[
State({"type": "parameter", "index": ALL}, "data"),
State({"type": "parameter", "index": ALL}, "value"),
State({"type": "parameter", "index": ALL}, "on"),
]
This makes my callback function very verbose and needs to regroup the parameters. While actually they are from several types of components, these trigger properties do not overlap. I vaguely remember that there was a post dedicated to this issue before, and someone has submitted a pr to change the name of the checklist’s values property to value, but I didn’t find it. However now that our component ecosystem is thriving, it is impossible and has no reason to require uniform property names.
I think passing a dictionary in is probably not easy to implement, so what if I specify the default trigger property in the id
or simply define a property for each component to represent the default trigger property?
like:
[
dcc.Input(id={"type": "parameter", "index": 1, "default": "value"}),
daq.BooleanSwitch(id={"type": "parameter", "index": 2}, default="on"),
dmc.Checkbox(id={"type": "parameter", "index": 3}, default="checked"),
]
Then the triggers can be simplified to:
[
State({"type": "parameter", "index": ALL}, DEFAULT),
]
A callback might look like this.
@app.callback(
Output(graph_1, "figure"),
Input({"type": "parameter", "index": ALL}, DEFAULT),
State({"type": "parameter", "index": ALL}, "id"),
)
def update(values, ids):
params = {j["index"]: values[i] for i, j in enumerate(ids)}
fig = do_something(**params)
return fig
Or we can compose it before passing in.
@app.callback(
Output(graph_1, "figure"),
group=(
[
Input({"type": "parameter", "index": ALL}, DEFAULT),
State({"type": "parameter", "index": ALL}, "id")["index"],
]
),
)
def update(params):
fig = do_something(**params)
return fig
Is this possible?