I have general questions about how callbacks work. As per examples on Plotly website, a common convention (or maybe correct way) of writing callbacks looks like this:
Is it possible to define a function with *args or **kwargs? I’m asking this because, when I define a function explicitly with arguments, callback expects that those arguments are not empty from the beginning. I know, that I can avoid it by adding a control like this if argument is not None:, but it is not convenient.
@AIMPED , thanks for your answers. Regarding the second point, I wanted to avoid defining functions explicitly (i.e., def some_function:). But if it is the way callbacks work, the code will still look complicated, keeping all these defs in one file and having many callbacks.
hi @parvizalizada ,
You can define your callback without decorations. Just like this,
app.callback()(your_func)
Or
app.callback()(lambda x: your_func(x))
hi bro,
In fact, this does not break away from using decorators, it just takes away the sugar ‘@’. The real decorator name is wrap_func, and the parameters it passes in and returns are function pointers. That’s why you can see two pairs of brackets together. I usually use this syntax when I need a lambda there, but I’m more likely to write some arrow functions to a client callback.