Is additional parameters possible in call_back functions (attr,old,new)?

Hello everyone, first of all I would like to thank all of you especially friends taking care of Bokeh project; I have learned lots thanks to you all.
I am trying to write a call_back function (without JavaScript) in Bokeh Server. My current update function is currently working fine but I need to write an update function to be able to update more than one figures, glyphs and also labels; so I wonder whether it is possible to pass additional parameters to a usual update function:

The general update function I have found and am using is with this structure:
“”“def myupdate(attr, old, new):
lines for updating various attributes of figure, plot etc. “””

And the widget creation and linking lines of code are as follows:

“”" myselect = Select(title=“My Graph Title”, value=“MY COLUMN NAME_1”, options=list_of_my_column_names_to_be_passed)

myselect.on_change(“value”, myupdate)"""

Is it possible to add new parameters to update functions’ parameters? And if yes, how should I call this function later on? Please see question marks ? below to be able comment:

“”“def myupdate(attr, old, new, ?,?,?): #New parameters to be added to function
lines for updating various attributes of figure, plot etc. “””

And in on_change function linking line:
“”“myselect.on_change(“value”, myupdate(?,?,?,?,?,?)#New parameters to be passed to function with default attr, old,new values
By the way, I do not know what to pass to these functions as (attr, old, new) values either.
I will deeply appreciate any of your comments and help.
Kind Regards.
Tansu B.

You can use stdlib functools.partial to bake in extra parameters. See

Also, in the future, please use code formatting so that the code is intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)


Regarding …

If I understand the question here, the point is that your user code does not explicitly call the callback function and you do not need to worry about passing anything here. The bokeh callback machinery takes care of keeping track of these things.

When you set up an on-change callback with “value” as the attribute, bokeh will invoke the callback for the subject widget. The attr argument will be populated with the attribute of the widget being acted upon, e.g. value property; the old argument will include the prior/current setting of the property (value in this illustration); and the new argument will indicate what the updated property setting is.

Dear Bryan, Thanks a lot for your answer. Though I did not quite grasp the method you are recommending; I will have a look at it deeply and will come back with questions if any. By the way, my apologies for using the wrong format while indicating my code; I know your sensitivity however apparently I misunderstood what I should be doing. I think I understood now. Regards. Tansu B.

Dear _jm, Thanks a lot for your answer. You are right that normally we do not need to pass values directly to these functions. When I need to add new parameters, what should I be doing was my question because I want to re-use these functions within my code for several other figures etc.
I think I did not get what I should be doing from your answer; sorry if this is due to my lack of experience or knowledge. Again, thank you. Regards. Tansu B.

Dear Bryan,
I solved after your help, thank you very much.
I appreciate.
Kind Regards. Tansu B.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.