☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Dynamically change BoxSelectTool overlay BoxAnnotation when drawing a box

Community Support
beder
beder

Hi all,

How can I dynamically update the Box Annotation overlay of the BoxSelectTool when drawing a box on a bokeh plot? After a certain value has been exceeded for the width/height of the box, I need to change the line color to red. Currently it is black.

I do not mean I want to change the styling of the glyph of the resulting selection or the resulting outline box when you release your mouse. I want to change the color of the overlay of the BoxSelectTool outline box itself-- the one that appears when you are clicking (holding mouse1) and dragging to create the selection box on a bokeh plot.

Thank you.

⌁   Link to post
beder
beder

Hi Bryan thank you for the reply. Yes, I can access the box annotation of the BoxSelectTool of my plot through the .overlay attribute. However, I believe I need to do something on the javascript side to update the color dynamically when someone is holding click and dragging the mouse when using the BoxSelectTool. However, I’m not sure how to do this.

I’m sorry my brain is a bit to slow to understand how the post you directed me to helps in my case.

I am performing a selectiongeometry. When the event.geometry sx and sy values exceed a certain number, I would like to change the outline of the active box associating with the boxselecttool to red.

Edit:
I have updated the BoxSelectTool attribute “select_every_mousemove” to be True. And then
I used the following code to access the attribute of the box annotation:
select_overlay = plot.select_one(BoxSelectTool).overlay
select_overlay.fill_color = “blue”

I can now change the color of the selection box dynamically.
However, the issue I have now is that the geometry selection appears to be arbitrary and does not correspond to the final movement of the mouse that is made before mouse1 is released.

Thanks.

⌁   Link to post
Bryan
Bryan

@beder it would really help to focus this discussion if you provide a Minimal Reproducible Example. E.g. I don’t really have any idea what this statement means

However, the issue I have now is that the geometry selection appears to be arbitrary and does not correspond to the final movement of the mouse that is made before mouse1 is released.

Edit: also, please make sure to use code formatting so that the code is highlighted and intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)

⌁   Link to post

End of archived discussion · Replies are disabled