Manual Label Bokeh -> hide click removes everything

Hi,

How come in the code below if I want to hide just one of the labels, it takes all of them out. Is it possible to let it know how to seperate them and only hide the one the user clicks on?


from bokeh.models import Legend, LegendItem
from bokeh.plotting import figure, show

p = figure()
r = p.multi_line([[1,2,3], [1,2,3]], [[1,3,2], [3,4,3]],
                 color=["orange", "red"], line_width=4)

legend = Legend(items=[
    LegendItem(label="orange", renderers=[r], index=0),
    LegendItem(label="red", renderers=[r], index=1),
])
p.add_layout(legend)
p.legend.click_policy="hide"
show(p)

I assume by “hide one of the labels” you mean “hide one of the lines”.
The legend click policy operates at the renderer level, namely the "hide" policy just makes your mouse clicks toggle the renderer.visible property.

You have to use multiple renderers if you want to hide them independently.