The code below shows a minimum working example. It’s run with bokeh serve --show <filename> (Bokeh v0.11.0). Here is the problem: when the curdoc().add_periodic_callback is not active, clicking on the “Line visible” checkbox does not affect whether the line is visible in the plot. However, as soon as the button is clicked, which sets curdoc().add_periodic_callback, the line becomes visible or not depending on the state of line.glyph.visible.
Note that if I uncomment the two lines in the function checkbox_group_handler that set line.glyph.line_alpha, then checking and unchecking the checkbox causes the line to immediately become visible or invisible, respectively.
Why doesn’t setting line.glyph.visible immediately act on the line? Is there something else I need to call to make it immediately render the line according to its visible property?
Thanks,
Greg
from bokeh.plotting import figure, curdoc, vplot, hplot
from bokeh.models.widgets import Toggle, CheckboxGroup
import numpy as np
ii = 0
periodic_callback_time_ms = 100
x = np.linspace(0,6,501)
y = np.cos(2*np.pi*x)
p = figure(x_range=(0,6), y_range=(-1.1,1.4))
ll = p.line(x, y, line_width=2, color="blue")
tt = p.text(0.5, 1.2, text=['counter = {}'.format(ii)],
text_align="left", text_font_size="10pt")
# Set up checkboxes to show/hide line
def checkbox_group_handler(active):
if 0 in active:
ll.glyph.visible = True
#ll.glyph.line_alpha = 1.0
else:
ll.glyph.visible = False
#ll.glyph.line_alpha = 0.0
checkbox_group = CheckboxGroup(labels=["Line visible"], active=[0])
checkbox_group.on_click(checkbox_group_handler)
# Set up toggle button & callback function
def toggle_handler(active):
if active:
toggle.label = 'Stop'
checkbox_group.disabled = True
curdoc().add_periodic_callback(update, periodic_callback_time_ms)
else:
toggle.label = 'Start'
checkbox_group.disabled = False
curdoc().remove_periodic_callback(update)
toggle = Toggle(label="Start", type="success")
toggle.on_click(toggle_handler)
toggle.active = False
layout = vplot(toggle, checkbox_group, p)
def update():
global ii
ii += 1
tt.data_source.data["text"] = ['counter = {}'.format(ii)]
in the place I linked above (that you test works, but it should) then I would be amenable to adding it as a "quick fix" pending some more comprehensive cleanup and refactoring around properties, because having "visible" work would be extremely useful in many areas. Ideally a PR would also have an example that shows it being used and/or documentation support in the user guide.
The code below shows a minimum working example. It's run with `bokeh serve --show <filename>` (Bokeh v0.11.0). Here is the problem: when the `curdoc().add_periodic_callback` is not active, clicking on the "Line visible" checkbox does not affect whether the line is visible in the plot. However, as soon as the button is clicked, which sets `curdoc().add_periodic_callback`, the line becomes visible or not depending on the state of `line.glyph.visible`.
Note that if I uncomment the two lines in the function `checkbox_group_handler` that set `line.glyph.line_alpha`, then checking and unchecking the checkbox causes the line to immediately become visible or invisible, respectively.
Is there something else I need to call to make it immediately render the line according to its `visible` property?
Thanks,
Greg
from bokeh.plotting import figure, curdoc, vplot, hplot
from bokeh.models.widgets import Toggle, CheckboxGroup
import numpy as np
ii = 0
periodic_callback_time_ms = 100
x = np.linspace(0,6,501)
y = np.cos(2*np.pi*x)
p = figure(x_range=(0,6), y_range=(-1.1,1.4))
ll = p.line(x, y, line_width=2, color="blue")
tt = p.text(0.5, 1.2, text=['counter = {}'.format(ii)],
text_align="left", text_font_size="10pt")
# Set up checkboxes to show/hide line
def checkbox_group_handler(active):
if 0 in active:
ll.glyph.visible = True #ll.glyph.line_alpha = 1.0
else:
ll.glyph.visible = False #ll.glyph.line_alpha = 0.0
checkbox_group = CheckboxGroup(labels=["Line visible"], active=[0])
checkbox_group.on_click(checkbox_group_handler)
# Set up toggle button & callback function
def toggle_handler(active):
if active:
toggle.label = 'Stop'
checkbox_group.disabled = True
curdoc().add_periodic_callback(update, periodic_callback_time_ms)
else:
toggle.label = 'Start'
checkbox_group.disabled = False
curdoc().remove_periodic_callback(update)
toggle = Toggle(label="Start", type="success")
toggle.on_click(toggle_handler)
toggle.active = False
layout = vplot(toggle, checkbox_group, p)
def update():
global ii
ii += 1
tt.data_source.data["text"] = ['counter = {}'.format(ii)]