I am developing Bokeh Server Application. I am using Bokeh 0.12.15
.
Problem description
I have a bunch of figures plotted as you can see in the following image. When I select some points points some profile lines should be drawn in all the plots. But the problem is that they crash as you can see in this image.
If I zoom out on the two figures they become normal again. I thinks it is a synchronization issue.
I have a ColumnDataSource (CDS) available for all the plots. Each profile has its own CDS.
This is the code snippet where I update the source data for the profile lines and where I recreate the CDSview with the selected indexes for the profile circles. This code is executed once per plot. If there are 4 plots in the form and there are 3 profiles per plot, there will be 24 updates (one per CDS) if the user make some selection. Is there a way to update everything at once to avoid this issue?
prof_len = len(prof_cds)
prof_to_show = []
for i in range(prof_len):
pos = NPROF - i - 1
self.prof_lines[pos].data_source.data = prof_cds[i].data
view = CDSView(source=self.env.source, filters=[IndexFilter(prof_indexes[i])])
self.prof_circles[pos].view = view
prof_to_show.append(pos)
In fact if I do this and I make a pause with sleep the profile lines are working well
prof_len = len(prof_cds)
prof_to_show = []
import time
for i in range(prof_len):
pos = NPROF - i - 1
self.prof_lines[pos].data_source.data = prof_cds[i].data
lg.info('-- WAITING FOR UPDATE')
time.sleep(2)
view = CDSView(source=self.env.source, filters=[IndexFilter(prof_indexes[i])])
self.prof_circles[pos].view = view
prof_to_show.append(pos)
Failed workaround
Bryan (Bokeh developer) told me to use the hold
method, but the same problem appears
I've only had a chance to barely glance at this, but offhand to answer your last question, perhaps
hold
andunhold
would be useful to batch thing more: https://github.com/bokeh/bokeh/blob/master/examples/howto/hold_app.py
self.env.doc.hold('combine')
for p_obj in self.env.bk_plots:
p_obj.plot_profile_lines(new.indices)
self.env.doc.unhold()
Conclusion
I reckon the problem here is that I am using a CDS for the points and a different CDS for the profiles lines. I would like to use the same and apply some CDSView, But it is not possible due to this filtering behaviour. So the only way to achieve this is to use only one CDS as it is describe in this answer? Then, I would need to add many columns to the current source and most of the data of these columns would have NaN
values, it is kind of ugly.
Is there a better way to do this?
Update 04/12/2018
- I get errors with
time.sleep
as well. - I am going to try to plot the profiles in a different way, maybe using one CDS for them and several CDSViews, maybe using segments rather than lines.