Bokeh Serve - updating plots using bokeh widgets

Hi

I am using bokeh version 0.11.1 and running a python script using bokeh serve (eg. bokeh serve script.py) to render 4 bokeh plot figures each with 8-10 line glyphs as well as a bokeh widget checkbox group used for interacting and updated the plot figures.

When a checkbox is checked, a new line glyph is added to the plot and an entry is added to the legend if it hasn’t been created yet. When a checkbox is unchecked, I hide the line by changing the alpha attribute to 0 and remove the corresponding entry from the legend. If that same line that was hidden needs to be shown again, I change the alpha back to 1 and add the legend entry back.

This behavior works perfectly until I continuously check and uncheck boxes around 7-8 times. After this, the plots and lines start flickering randomly and the checkboxes don’t work at all anymore. Here’s the code I use to make the updates:

class LTVPlot(object):

def init(self, plot, lines, plot_legends, legend_labels, dataset):

self.plot = plot

self.lines = lines

self.plot_legends = plot_legends

self.legend_labels = legend_labels

self.dataset = dataset

self.handle = None

def add_handle(self, handle):

self.handle = handle

def update(self, indexes, push = True):

print(‘update_called’)

for i in range(len(self.lines)):

if self.lines[i] is not None:

self.lines[i].glyph.line_alpha = 0

self.plot.legend[0].legends =

legends_to_show =

legends_index_set = set(pick_legend_indexes(indexes, LINES_TO_SHOW-1))

for i, index in enumerate(indexes):

if self.lines[index] is None:

self.lines[index] = self.plot.line(

self.dataset.data[‘x%d’ % index], self.dataset.data[‘y%d’ % index],

legend = self.legend_labels.get(index, None),

alpha = 1,

line_width=DEFAULT_LINE_WIDTH,

line_color = pick_color(i, len(indexes) - 1))

self.plot_legends[index] = self.plot.legend[0].legends[0]

else:

self.lines[index].glyph.line_alpha = 1

self.lines[index].glyph.line_color = pick_color(i, len(indexes) - 1)

if index in legends_index_set:

legends_to_show.append(self.plot_legends[index])

self.plot.legend[0].legends = legends_to_show

When the flickering starts I don’t see anything printed to the js console. The update function isn’t being called either. What might be causing this issue?

Thanks,

Simon

I'm not sure offhand, I think it will require investigation, which means it will require real code to run and test with. Is it possible that you can isolate the behavior in a minimal complete script? In the mean time can you confirm that it's not executing the p.line(...) call more than you expect? As another test, can you confirm whether the behavior still happens if you get rid of all the legends and legend updating code? I'm also not quite clear on "start flickering randomly", do you mean just when they update, or in general, anytime?

One thing to mention, though I doubt it is the cause of your issue, is that it's probably (slightly) better to set the line_color to None, that will actually cause it to not attempt to render the line at all (not just render it, but invisibly).

Bryan

···

On Apr 22, 2016, at 1:50 PM, Simon Huang <[email protected]> wrote:

Hi

I am using bokeh version 0.11.1 and running a python script using bokeh serve (eg. bokeh serve script.py) to render 4 bokeh plot figures each with 8-10 line glyphs as well as a bokeh widget checkbox group used for interacting and updated the plot figures.

When a checkbox is checked, a new line glyph is added to the plot and an entry is added to the legend if it hasn't been created yet. When a checkbox is unchecked, I hide the line by changing the alpha attribute to 0 and remove the corresponding entry from the legend. If that same line that was hidden needs to be shown again, I change the alpha back to 1 and add the legend entry back.

This behavior works perfectly until I continuously check and uncheck boxes around 7-8 times. After this, the plots and lines start flickering randomly and the checkboxes don't work at all anymore. Here's the code I use to make the updates:

class LTVPlot(object):

    def __init__(self, plot, lines, plot_legends, legend_labels, dataset):
        self.plot = plot
        self.lines = lines
        self.plot_legends = plot_legends
        self.legend_labels = legend_labels
        self.dataset = dataset
        self.handle = None

    def add_handle(self, handle):
        self.handle = handle

    def update(self, indexes, push = True):
        print('update_called')
        for i in range(len(self.lines)):
            if self.lines[i] is not None:
                self.lines[i].glyph.line_alpha = 0

        self.plot.legend[0].legends =
        legends_to_show =
        legends_index_set = set(pick_legend_indexes(indexes, LINES_TO_SHOW-1))
        for i, index in enumerate(indexes):
            if self.lines[index] is None:
                self.lines[index] = self.plot.line(
                  self.dataset.data['x%d' % index], self.dataset.data['y%d' % index],
                  legend = self.legend_labels.get(index, None),
                  alpha = 1,
                  line_width=DEFAULT_LINE_WIDTH,
                  line_color = pick_color(i, len(indexes) - 1))
                self.plot_legends[index] = self.plot.legend[0].legends[0]
            else:
                self.lines[index].glyph.line_alpha = 1
                self.lines[index].glyph.line_color = pick_color(i, len(indexes) - 1)
            if index in legends_index_set:
                legends_to_show.append(self.plot_legends[index])

        self.plot.legend[0].legends = legends_to_show

When the flickering starts I don't see anything printed to the js console. The update function isn't being called either. What might be causing this issue?

Thanks,
Simon

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1f572cc9-b0fa-4b97-a241-fdad8dc5922c%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the help Bryan. By “start flicking randomly” I mean all the legend entries and lines both start appearing and disappearing continuously very quickly and none of the updates from the checkboxes work anymore. I removed the legend updates and the problem has went away. Would you have any clue for why this is the case?

Thanks!

···

On Friday, 22 April 2016 12:01:50 UTC-7, Bryan Van de ven wrote:

I’m not sure offhand, I think it will require investigation, which means it will require real code to run and test with. Is it possible that you can isolate the behavior in a minimal complete script? In the mean time can you confirm that it’s not executing the p.line(…) call more than you expect? As another test, can you confirm whether the behavior still happens if you get rid of all the legends and legend updating code? I’m also not quite clear on “start flickering randomly”, do you mean just when they update, or in general, anytime?

One thing to mention, though I doubt it is the cause of your issue, is that it’s probably (slightly) better to set the line_color to None, that will actually cause it to not attempt to render the line at all (not just render it, but invisibly).

Bryan

On Apr 22, 2016, at 1:50 PM, Simon Huang [email protected] wrote:

Hi

I am using bokeh version 0.11.1 and running a python script using bokeh serve (eg. bokeh serve script.py) to render 4 bokeh plot figures each with 8-10 line glyphs as well as a bokeh widget checkbox group used for interacting and updated the plot figures.

When a checkbox is checked, a new line glyph is added to the plot and an entry is added to the legend if it hasn’t been created yet. When a checkbox is unchecked, I hide the line by changing the alpha attribute to 0 and remove the corresponding entry from the legend. If that same line that was hidden needs to be shown again, I change the alpha back to 1 and add the legend entry back.

This behavior works perfectly until I continuously check and uncheck boxes around 7-8 times. After this, the plots and lines start flickering randomly and the checkboxes don’t work at all anymore. Here’s the code I use to make the updates:

class LTVPlot(object):

def __init__(self, plot, lines, plot_legends, legend_labels, dataset):
    self.plot = plot
    self.lines = lines
    self.plot_legends = plot_legends
    self.legend_labels = legend_labels
    self.dataset = dataset
    self.handle = None
def add_handle(self, handle):
    self.handle = handle
def update(self, indexes, push = True):
    print('update_called')
    for i in range(len(self.lines)):
        if self.lines[i] is not None:
            self.lines[i].glyph.line_alpha = 0
    self.plot.legend[0].legends = []
    legends_to_show = []
    legends_index_set = set(pick_legend_indexes(indexes, LINES_TO_SHOW-1))
    for i, index in enumerate(indexes):
        if self.lines[index] is None:
            self.lines[index] = self.plot.line(
              self.dataset.data['x%d' % index], self.dataset.data['y%d' % index],
              legend = self.legend_labels.get(index, None),
              alpha = 1,
              line_width=DEFAULT_LINE_WIDTH,
              line_color = pick_color(i, len(indexes) - 1))
            self.plot_legends[index] = self.plot.legend[0].legends[0]
        else:
            self.lines[index].glyph.line_alpha = 1
            self.lines[index].glyph.line_color = pick_color(i, len(indexes) - 1)
        if index in legends_index_set:
            legends_to_show.append(self.plot_legends[index])
    self.plot.legend[0].legends = legends_to_show

When the flickering starts I don’t see anything printed to the js console. The update function isn’t being called either. What might be causing this issue?

Thanks,

Simon


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 [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1f572cc9-b0fa-4b97-a241-fdad8dc5922c%40continuum.io.

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

Simon,

I am afraid I don't offhand, and that it will require real investigation. Is it possible that you can share are complete, minimal, runnable example that reproduces the problem?

Thanks,

Bryan

···

On Apr 25, 2016, at 2:41 PM, [email protected] wrote:

Thanks for the help Bryan. By "start flicking randomly" I mean all the legend entries and lines both start appearing and disappearing continuously very quickly and none of the updates from the checkboxes work anymore. I removed the legend updates and the problem has went away. Would you have any clue for why this is the case?

Thanks!

On Friday, 22 April 2016 12:01:50 UTC-7, Bryan Van de ven wrote:
I'm not sure offhand, I think it will require investigation, which means it will require real code to run and test with. Is it possible that you can isolate the behavior in a minimal complete script? In the mean time can you confirm that it's not executing the p.line(...) call more than you expect? As another test, can you confirm whether the behavior still happens if you get rid of all the legends and legend updating code? I'm also not quite clear on "start flickering randomly", do you mean just when they update, or in general, anytime?
  
One thing to mention, though I doubt it is the cause of your issue, is that it's probably (slightly) better to set the line_color to None, that will actually cause it to not attempt to render the line at all (not just render it, but invisibly).

Bryan

> On Apr 22, 2016, at 1:50 PM, Simon Huang <[email protected]> wrote:
>
> Hi
>
> I am using bokeh version 0.11.1 and running a python script using bokeh serve (eg. bokeh serve script.py) to render 4 bokeh plot figures each with 8-10 line glyphs as well as a bokeh widget checkbox group used for interacting and updated the plot figures.
>
> When a checkbox is checked, a new line glyph is added to the plot and an entry is added to the legend if it hasn't been created yet. When a checkbox is unchecked, I hide the line by changing the alpha attribute to 0 and remove the corresponding entry from the legend. If that same line that was hidden needs to be shown again, I change the alpha back to 1 and add the legend entry back.
>
> This behavior works perfectly until I continuously check and uncheck boxes around 7-8 times. After this, the plots and lines start flickering randomly and the checkboxes don't work at all anymore. Here's the code I use to make the updates:
>
> class LTVPlot(object):
>
> def __init__(self, plot, lines, plot_legends, legend_labels, dataset):
> self.plot = plot
> self.lines = lines
> self.plot_legends = plot_legends
> self.legend_labels = legend_labels
> self.dataset = dataset
> self.handle = None
>
> def add_handle(self, handle):
> self.handle = handle
>
> def update(self, indexes, push = True):
> print('update_called')
> for i in range(len(self.lines)):
> if self.lines[i] is not None:
> self.lines[i].glyph.line_alpha = 0
>
> self.plot.legend[0].legends =
> legends_to_show =
> legends_index_set = set(pick_legend_indexes(indexes, LINES_TO_SHOW-1))
> for i, index in enumerate(indexes):
> if self.lines[index] is None:
> self.lines[index] = self.plot.line(
> self.dataset.data['x%d' % index], self.dataset.data['y%d' % index],
> legend = self.legend_labels.get(index, None),
> alpha = 1,
> line_width=DEFAULT_LINE_WIDTH,
> line_color = pick_color(i, len(indexes) - 1))
> self.plot_legends[index] = self.plot.legend[0].legends[0]
> else:
> self.lines[index].glyph.line_alpha = 1
> self.lines[index].glyph.line_color = pick_color(i, len(indexes) - 1)
> if index in legends_index_set:
> legends_to_show.append(self.plot_legends[index])
>
> self.plot.legend[0].legends = legends_to_show
>
>
> When the flickering starts I don't see anything printed to the js console. The update function isn't being called either. What might be causing this issue?
>
> Thanks,
> Simon
>
> --
> 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/1f572cc9-b0fa-4b97-a241-fdad8dc5922c%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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6aaa3261-58b0-4893-abed-95589fd1f592%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.