dash icon indicating copy to clipboard operation
dash copied to clipboard

[Feature Request] Advanced props in `dash.callback`

Open xhluca opened this issue 3 years ago • 2 comments

I vaguely remember that Chris might have mentioned this before (if so please link issue), but it would be nice if in dash.callback(id, props) we can use some advanced structure for props. E.g.

@dash.callback(Output(...), Input(my_component.id, ["children", "id"]))
def func(lst):
  print(lst[0])  # => the content of children
  print(lst[1]) # => the ID

Or a dictionary could also work:

@dash.callback(Output(...), Input(my_component.id, {"foo": "children", "bar": "id"}))
def func(di):
  print(di['foo'])  # => the content of children
  print(di['bar']) # => the ID

xhluca avatar May 18 '22 05:05 xhluca

Oh interesting, these input structures are already possible via flexible callback signatures but for the specific case of multiple props of the same component these are nice shorthands, and seem quite intuitive to me. Just like flexible callbacks, seems like this applies to outputs as well.

alexcjohnson avatar May 19 '22 02:05 alexcjohnson

I think it's especially useful when combined with pattern matching callback, which tend to be rather long to write. This could avoid repetition.

xhluca avatar May 19 '22 16:05 xhluca