☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

bokeh server: Is there a way to "manually" sync all models between python and JS

Community Support
Sebastien_Roche
Sebastien_Roche

Is there something I can do to force all models to be synced between the JS side and the python side when using a bokeh server?

In a bokeh server app I update a ColumnDataSource with a CustomJS callback, the source data has initially empty columns
This works well and the new data is displayed in the browser.

I also have a python on_change callback for the selected attribute of the source.

The callback triggers when a point is clicked, and the selected indices of the selection are correct, but the source model itself is still empty.

I use 0.12.10, and I understand the selection is now a model and this specific issue might have been fixed.

But I would still like to know if there is a way to do a “manual” general python-JS sync

Thanks

⌁   Link to post
Bryan
Bryan

Hi,

There is not. Every change you make triggers a change sync event already. It's possible what you are seeing is simply an order of updates issue. If you are looking to simply batch updates in a way that gives you more control, or because you want to coalesce events together, the hold/unhold functions may be useful (I can't quite tell from your description if it will be useful for you or not):

  bokeh.document — Bokeh 3.3.2 Documentation

  https://github.com/bokeh/bokeh/blob/master/examples/howto/hold_app.py

Thanks,

Bryan

···

On Sep 28, 2018, at 08:03, Sébastien Roche <sebastienroche11@gmail.com> wrote:

Is there something I can do to force all models to be synced between the JS side and the python side when using a bokeh server?

In a bokeh server app I update a ColumnDataSource with a CustomJS callback, the source data has initially empty columns
This works well and the new data is displayed in the browser.
I also have a python on_change callback for the selected attribute of the source.
The callback triggers when a point is clicked, and the selected indices of the selection are correct, but the source model itself is still empty.

I use 0.12.10, and I understand the selection is now a model and this specific issue might have been fixed.
But I would still like to know if there is a way to do a "manual" general python-JS sync

Thanks

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/cbb7b9d1-f174-45d8-a4a5-6b10798adef7%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
Sebastien_Roche
Sebastien_Roche

Thanks for the answer !

Here is a specific small example:

from bokeh.models import ColumnDataSource, CustomJS, Button
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import Row

def callback(attr,old,new):
source = curdoc().select_one({‘name’:‘source’})
print source.data

source = ColumnDataSource(data={‘x’:,‘y’:},name=‘source’)

fig = figure(tools=‘tap’)
fig.scatter(‘x’,‘y’,size=10,source=source)

source.on_change(‘selected’,callback)

button = Button(label=‘test’,width=100)

button_code = “”"
var data = source.data;
data[‘x’] = ;
data[‘y’] = ;
for (i=0;i<10;i++){
data[‘x’].push(i);
data[‘y’].push(i);
}
source.change.emit();
“”"

button.callback = CustomJS(args={‘source’:source},code=button_code)

curdoc().add_root(Row(fig,button))

``

After clicking the button the plot is updated with the points

After clicking on a point the terminal output is:
{‘y’: , ‘x’: }

``

⌁   Link to post
Bryan
Bryan

Oh, in this case it is due to the fact that we cannot detect changes "inside" arrays, and you are only making those kinds of changes. This is an unfortunate JS limitation, I am not aware of anything that can be done about it. The workaround is to set a real, full property, e.g. "source.data = data", which is something the property system can detect:

button_code = """
var data = source.data;
data['x'] = ;
data['y'] = ;
for (i=0;i<10;i++){
data['x'].push(i);
data['y'].push(i);
}
source.data = data;
source.change.emit();
"""

···

On Sep 28, 2018, at 12:02, Sébastien Roche <sebastienroche11@gmail.com> wrote:

Thanks for the answer !

Here is a specific small example:

from bokeh.models import ColumnDataSource, CustomJS, Button
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import Row

def callback(attr,old,new):
    source = curdoc().select_one({'name':'source'})
    print source.data

source = ColumnDataSource(data={'x':,'y':},name='source')

fig = figure(tools='tap')
fig.scatter('x','y',size=10,source=source)

source.on_change('selected',callback)

button = Button(label='test',width=100)

button_code = """
var data = source.data;
data['x'] = ;
data['y'] = ;
for (i=0;i<10;i++){
data['x'].push(i);
data['y'].push(i);
}
source.change.emit();
"""

button.callback = CustomJS(args={'source':source},code=button_code)

curdoc().add_root(Row(fig,button))

After clicking the button the plot is updated with the points
After clicking on a point the terminal output is:
{'y': , 'x': }

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/717f218f-6cc4-4a0d-a364-1dd7fc61f0ce%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
chupach1
chupach1

Hello Bryan,

is there a way to access the event queue before calling “unhold”, e.g. to remove some events from the queue ?

thanks

···

On Friday, September 28, 2018 at 7:05:57 PM UTC+2, Bryan Van de ven wrote:

Hi,

There is not. Every change you make triggers a change sync event already. It’s possible what you are seeing is simply an order of updates issue. If you are looking to simply batch updates in a way that gives you more control, or because you want to coalesce events together, the hold/unhold functions may be useful (I can’t quite tell from your description if it will be useful for you or not):

    [https://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.document.Document.hold](https://bokeh.pydata.org/en/latest/docs/reference/document.html#bokeh.document.document.Document.hold)



    [https://github.com/bokeh/bokeh/blob/master/examples/howto/hold_app.py](https://github.com/bokeh/bokeh/blob/master/examples/howto/hold_app.py)

Thanks,

Bryan

On Sep 28, 2018, at 08:03, Sébastien Roche sebastie...@gmail.com wrote:

Is there something I can do to force all models to be synced between the JS side and the python side when using a bokeh server?

In a bokeh server app I update a ColumnDataSource with a CustomJS callback, the source data has initially empty columns

This works well and the new data is displayed in the browser.

I also have a python on_change callback for the selected attribute of the source.

The callback triggers when a point is clicked, and the selected indices of the selection are correct, but the source model itself is still empty.

I use 0.12.10, and I understand the selection is now a model and this specific issue might have been fixed.

But I would still like to know if there is a way to do a “manual” general python-JS sync

Thanks

–
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/cbb7b9d1-f174-45d8-a4a5-6b10798adef7%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
Bryan
Bryan

Hi,

In Python there is always a way. They are in Document._held_events, however I would personally regard mucking with that as a questionable idea. We may for instance change private APIs and attributes at any time with no warning.

Thanks,

Bryan

···

On Sep 29, 2018, at 03:09, chupach <mathieur1507@gmail.com> wrote:

Hello Bryan,

is there a way to access the event queue before calling "unhold", e.g. to remove some events from the queue ?

thanks

On Friday, September 28, 2018 at 7:05:57 PM UTC+2, Bryan Van de ven wrote:
Hi,

There is not. Every change you make triggers a change sync event already. It's possible what you are seeing is simply an order of updates issue. If you are looking to simply batch updates in a way that gives you more control, or because you want to coalesce events together, the hold/unhold functions may be useful (I can't quite tell from your description if it will be useful for you or not):

        bokeh.document — Bokeh 3.3.2 Documentation

        https://github.com/bokeh/bokeh/blob/master/examples/howto/hold_app.py

Thanks,

Bryan

> On Sep 28, 2018, at 08:03, Sébastien Roche <sebastie...@gmail.com> wrote:
>
> Is there something I can do to force all models to be synced between the JS side and the python side when using a bokeh server?
>
> In a bokeh server app I update a ColumnDataSource with a CustomJS callback, the source data has initially empty columns
> This works well and the new data is displayed in the browser.
> I also have a python on_change callback for the selected attribute of the source.
> The callback triggers when a point is clicked, and the selected indices of the selection are correct, but the source model itself is still empty.
>
> I use 0.12.10, and I understand the selection is now a model and this specific issue might have been fixed.
> But I would still like to know if there is a way to do a "manual" general python-JS sync
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/cbb7b9d1-f174-45d8-a4a5-6b10798adef7%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0c4e9a18-2352-4e26-9d49-07ddc6fb4cba%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post

End of archived discussion · Replies are disabled