I like the fact that I can use the legend to toggle lines / points on and off. This is really convenient.
When I tried to also use the legend to toggle BoxAnnotations on/off by adding them to the figure.legend so I could click on them, I got the following error:
error handling message Message ‘PATCH-DOC’ (revision 1): ValueError("expected an element of List(Instance(GlyphRenderer)), got seq with invalid items [BoxAnnotation(id=‘652d8363-2e2a-4ca9-ba98-343054754ff2’, …), BoxAnnotation(id=‘9f4a8e05-83ad-4dad-adac-2268ef19f1c7’, …)
Looking into it further, this approach might not work since BoxAnnotation subclasses Annotation which subclasses Renderer instead of GlyphRenderers… This means that BoxAnnotations and GlyphRenderers tree up through different branches to the base Renderer class. As such it seems that the Legend in its current form can only turn on and off Glyphs?
Thanks for any help or advise you may be able to provide.
For reference, I was trying to do something like the following and it failed on the “legend_item = LegendItem” line with the error above.
f = figure(title='some title') f.line(x='x', y='y', source=source, legend="my line") box_annotation_list = some_function_which_gives_me_box_annotations() legend_item = LegendItem(label="new legend item", renderers=box_annotation_list) # this might not be right since .items is a List() f.legend.items.extend(legend_item)