Unable to pass visibility as part of a ColumnDataSource source

Hi,

When I try to set the ‘visible’ attribute from a ColumnDataSource as per the following example:

from bokeh.plotting import figure, show
from bokeh.io import output_notebook
from bokeh.models import ColumnDataSource

output_notebook()

x = [1,2,3,4,5]
y = [10, 20, 30, 40, 50]
visiblity = [True, True, False, True, False]

source = ColumnDataSource(dict(
    x = x,
    y = y,
    vis = visiblity
))

p = figure()

p.circle(x='x', y='y',
          fill_color='red', fill_alpha=0.6, size=10,
          line_color=None, source=source)

p.triangle(x='x', y='y',
          fill_color=None, fill_alpha=1, size=20, visible='vis',
          line_color='blue', source=source)

show(p)

I get the following error:

ValueError: failed to validate GlyphRenderer(id='p1614', ...).visible: expected a value of type bool or bool_, got vis of type str

Any ideas about how to fix this?

visibility is not a vectorized property that can be driven by a CDS, it is just a single boolean that controls the entire glyph. For this use case, users would generally use the “alpha” properties, which can be vectorized.

1 Like

Makes sense. Thank you!