Setting the Glyph visible property

I m trying to create a plot to display circle based on the status of checkbox. But not able to do so below is the code I m using

Bokeh version -2.2.3

from bokeh.layouts import column, row
from bokeh.plotting import figure, curdoc
from bokeh.models import HoverTool, Slider, CheckboxGroup

x=2
y=1

plot = figure(plot_height=300, plot_width=300,
              x_range=(-x, x), y_range=(-y, y))
			  
shapes_list = [plot.circle(
    x=0, y=0, size=2, fill_alpha=.1), 'Square', 'Rectangle']

def display_shapes(flag):
    for i in flag:
        print(i, shapes_list[i], type(shapes_list[i]), shapes_list[i].glyph)
        shapes_list[i].visible = True

def update_data(attrname, old, new):
    x = xslider.value
    y = yslider.value
    x_plist = []
    y_plist = []
    z = x if x >= y else y
    for j in range(-x, x+1, 1):
        for i in range(-y, y+1, 2):
            x_plist.append([j, j, j+1, j+1])
            if i == -y:
                y_plist.append([i+2, i+2, i+2, i])
            else:
                y_plist.append([i-2, i, i, i-2])
            if j == 6:
                print(j, j, j+1, j+1)
                print(i-2, i, i, i-2)

    print(shapes.active)
    display_shapes(shapes.active)

    plot.x_range.start = -z + 1
    plot.y_range.start = -z+1
    plot.x_range.end = z+1
    plot.y_range.end = z+1
    #hoverp = HoverTool(tooltips=[('$x-$y','@xs-@ys')], renderers=[pt])
    pt.data_source.data['xs'] = x_plist
    pt.data_source.data['ys'] = y_plist

x_plist = []
y_plist = []

for j in range(-x, x+1, 1):
    for i in range(-y, y+1, 2):
        x_plist.append([j, j, j+1, j+1])
        if i == -18:
            y_plist.append([i+2, i+2, i+2, i])
        else:
            y_plist.append([i-2, i, i, i-2])
			
xs = x_plist
ys = y_plist
shapes = CheckboxGroup(labels=['Circle', 'Square', 'Rectangle'])
xslider = Slider(title="X", value=5, start=0, end=10, step=1)
yslider = Slider(title="Y", value=6, start=0, end=10, step=1)

pt = plot.patches(xs, ys, fill_color='white', line_color='grey', line_alpha=.5)
hoverp = HoverTool(tooltips=[('$x-$y', '@hs')], renderers=[pt])
plot.add_tools(hoverp)
plot.axis.visible = True
plot.grid.visible = False

for w in [xslider, yslider]:
    w.on_change('value', update_data)

shapes.on_change('active', update_data)
curdoc().add_root(row(plot, column(xslider, yslider, shapes), width=800))

Hi @Ashish_Kumar please edit your post to fix up the code formatting so that the code is more intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks) and without all the extra whitespace every other line.

@Ashish_Kumar

Your circle is visible by default when you generate the renderer, so you could set the visible property to False during creation so that the callback actually has an effect of showing it when the checkbox is selected by the user.

As to why you do not see it when the client first accesses the server … bokeh models have a level property, which for glyph renderers is ‘glyph’. Patches and circles are all rendered on the same level by default, which means the order in which you draw them determines which items are on top for a given renderer level.

Your code renders the circle first and then the patches. So the circle is underneath the patches and is not visible (esp. given that the fill alpha of the patches is 1.0, i.e. no transparency). You can reorder the operations to draw the patches and circle, change the fill alpha of the patches, or something similar depending on your use case.

Hope this helps.

thanks _jm