Using Bokeh Server, I can add and delete box annotations no problem prior to the plot being displayed using some helper functions. However, once the plot is displayed to the user, I can add box annotations with call-backs, but can not delete the box annotations using callback buttons and the exact same helper functions. If it was a scope issue, I would expect add and delete to either both work, or both not work.
In detail:
To see what I mean, go to line 138 where the debugging code starts in the attached python file and follow the instructions for Debug 1,2,3,4 which are repeated here for clarity
It appears as if although the box annotations are added and they can be found immediately after adding while still within the scope of the add_box_annotations() function as seen by the output produced to standard out from line 65. However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96.
“However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96 even-though the box annotations are still displayed on the plot.”
···
On Monday, January 29, 2018 at 3:19:26 PM UTC-5, [email protected] wrote:
In short:
Using Bokeh Server, I can add and delete box annotations no problem prior to the plot being displayed using some helper functions. However, once the plot is displayed to the user, I can add box annotations with call-backs, but can not delete the box annotations using callback buttons and the exact same helper functions. If it was a scope issue, I would expect add and delete to either both work, or both not work.
In detail:
To see what I mean, go to line 138 where the debugging code starts in the attached python file and follow the instructions for Debug 1,2,3,4 which are repeated here for clarity
It appears as if although the box annotations are added and they can be found immediately after adding while still within the scope of the add_box_annotations() function as seen by the output produced to standard out from line 65. However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96.
#======================
initialize the layout
f = draw_plot3()
Debug 1:
uncommenting the following results in the expected behavior of box annotations
being added to the plot when the plot is first displayed to the user.
#add_box_annotations(f)
Debug 2:
uncommenting the previous along with following results in the expected behavior
of the box annotations being removed prior to the plot being displayed to the
user for the first time.
#clear_box_annotations(f)
Debug 3:
clicking on the “add” button results in the expected behavior of box annotations
being added.
Debug 4:
clicking on the “delete” button (with an annotation displayed) results in the
Also, if in your application the end number of annotations is fixed, I suggest to just toggle visible property of an annotation - it’s much simpler and much more reliable.
Regards,
Eugene
···
On Tuesday, January 30, 2018 at 4:04:13 AM UTC+7, James wrote:
minor edit in red…
“However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96 even-though the box annotations are still displayed on the plot.”
On Monday, January 29, 2018 at 3:19:26 PM UTC-5, [email protected] wrote:
In short:
Using Bokeh Server, I can add and delete box annotations no problem prior to the plot being displayed using some helper functions. However, once the plot is displayed to the user, I can add box annotations with call-backs, but can not delete the box annotations using callback buttons and the exact same helper functions. If it was a scope issue, I would expect add and delete to either both work, or both not work.
In detail:
To see what I mean, go to line 138 where the debugging code starts in the attached python file and follow the instructions for Debug 1,2,3,4 which are repeated here for clarity
It appears as if although the box annotations are added and they can be found immediately after adding while still within the scope of the add_box_annotations() function as seen by the output produced to standard out from line 65. However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96.
#======================
initialize the layout
f = draw_plot3()
Debug 1:
uncommenting the following results in the expected behavior of box annotations
being added to the plot when the plot is first displayed to the user.
#add_box_annotations(f)
Debug 2:
uncommenting the previous along with following results in the expected behavior
of the box annotations being removed prior to the plot being displayed to the
user for the first time.
#clear_box_annotations(f)
Debug 3:
clicking on the “add” button results in the expected behavior of box annotations
being added.
Debug 4:
clicking on the “delete” button (with an annotation displayed) results in the
My number of box annotations is not fixed. Sometimes none, sometimes 50. I will manage a list of box annotations and add more to the list on an as-needed basis. (Bryan Van de ven suggested toggling visibility in a related thread https://groups.google.com/a/continuum.io/forum/#!mydiscussions/bokeh/Exnb1oE6gz0, so I am slowly realizing that toggling is likely more reliable.)
Thanks for helping out a newbie so quick!
-james
···
On Tuesday, January 30, 2018 at 12:45:26 AM UTC-5, Eugene Pakhomov wrote:
Also, if in your application the end number of annotations is fixed, I suggest to just toggle visible property of an annotation - it’s much simpler and much more reliable.
Regards,
Eugene
On Tuesday, January 30, 2018 at 4:04:13 AM UTC+7, James wrote:
minor edit in red…
“However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96 even-though the box annotations are still displayed on the plot.”
On Monday, January 29, 2018 at 3:19:26 PM UTC-5, [email protected] wrote:
In short:
Using Bokeh Server, I can add and delete box annotations no problem prior to the plot being displayed using some helper functions. However, once the plot is displayed to the user, I can add box annotations with call-backs, but can not delete the box annotations using callback buttons and the exact same helper functions. If it was a scope issue, I would expect add and delete to either both work, or both not work.
In detail:
To see what I mean, go to line 138 where the debugging code starts in the attached python file and follow the instructions for Debug 1,2,3,4 which are repeated here for clarity
It appears as if although the box annotations are added and they can be found immediately after adding while still within the scope of the add_box_annotations() function as seen by the output produced to standard out from line 65. However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96.
#======================
initialize the layout
f = draw_plot3()
Debug 1:
uncommenting the following results in the expected behavior of box annotations
being added to the plot when the plot is first displayed to the user.
#add_box_annotations(f)
Debug 2:
uncommenting the previous along with following results in the expected behavior
of the box annotations being removed prior to the plot being displayed to the
user for the first time.
#clear_box_annotations(f)
Debug 3:
clicking on the “add” button results in the expected behavior of box annotations
being added.
Debug 4:
clicking on the “delete” button (with an annotation displayed) results in the
If you know the maximum number of annotations you will ever have, you could declare that many invisible ones, then update them and make them visible when you need them.
···
Le mardi 30 janvier 2018 08:00:18 UTC-5, James a écrit :
Thanks Eugene!
My number of box annotations is not fixed. Sometimes none, sometimes 50. I will manage a list of box annotations and add more to the list on an as-needed basis. (Bryan Van de ven suggested toggling visibility in a related thread https://groups.google.com/a/continuum.io/forum/#!mydiscussions/bokeh/Exnb1oE6gz0, so I am slowly realizing that toggling is likely more reliable.)
Thanks for helping out a newbie so quick!
-james
On Tuesday, January 30, 2018 at 12:45:26 AM UTC-5, Eugene Pakhomov wrote:
Also, if in your application the end number of annotations is fixed, I suggest to just toggle visible property of an annotation - it’s much simpler and much more reliable.
Regards,
Eugene
On Tuesday, January 30, 2018 at 4:04:13 AM UTC+7, James wrote:
minor edit in red…
“However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96 even-though the box annotations are still displayed on the plot.”
On Monday, January 29, 2018 at 3:19:26 PM UTC-5, [email protected] wrote:
In short:
Using Bokeh Server, I can add and delete box annotations no problem prior to the plot being displayed using some helper functions. However, once the plot is displayed to the user, I can add box annotations with call-backs, but can not delete the box annotations using callback buttons and the exact same helper functions. If it was a scope issue, I would expect add and delete to either both work, or both not work.
In detail:
To see what I mean, go to line 138 where the debugging code starts in the attached python file and follow the instructions for Debug 1,2,3,4 which are repeated here for clarity
It appears as if although the box annotations are added and they can be found immediately after adding while still within the scope of the add_box_annotations() function as seen by the output produced to standard out from line 65. However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96.
#======================
initialize the layout
f = draw_plot3()
Debug 1:
uncommenting the following results in the expected behavior of box annotations
being added to the plot when the plot is first displayed to the user.
#add_box_annotations(f)
Debug 2:
uncommenting the previous along with following results in the expected behavior
of the box annotations being removed prior to the plot being displayed to the
user for the first time.
#clear_box_annotations(f)
Debug 3:
clicking on the “add” button results in the expected behavior of box annotations
being added.
Debug 4:
clicking on the “delete” button (with an annotation displayed) results in the
I refactored the clear_box_annotations() function to use Bryan’s suggested means of using renderers.remove() and it looks like they are still hanging around after removal using this means of removal as well. So it indeed looks like there is an issue.
def get_my_box_annotation_renderer(f):
for i,r in enumerate(f.renderers):
if r.name == ‘my_box_annotation’:
print(’ found my_box_annotation at index:’ + str(i))
return r
return None
def clear_box_annotations(f):
print(“>>>clear_box_annotations”)
for i,r in enumerate(f.renderers):
if r.name == ‘my_box_annotation’:
print(" found my_box_annotation before clearing")
#f.renderers = [r for r in f.renderers if r.name != 'my_box_annotation']
try to get a my_box_annotation… if you find one, remove it.
while get_my_box_annotation_renderer(f):
f.renderers.remove(get_my_box_annotation_renderer(f))
for i,r in enumerate(f.renderers):
if r.name == ‘my_box_annotation’:
print(" found my_box_annotation after clearing")
print(“<<<clear_box_annotations”)
Thanks!
On Tuesday, January 30, 2018 at 12:45:26 AM UTC-5, Eugene Pakhomov wrote:
Also, if in your application the end number of annotations is fixed, I suggest to just toggle visible property of an annotation - it’s much simpler and much more reliable.
Regards,
Eugene
On Tuesday, January 30, 2018 at 4:04:13 AM UTC+7, James wrote:
minor edit in red…
“However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96 even-though the box annotations are still displayed on the plot.”
On Monday, January 29, 2018 at 3:19:26 PM UTC-5, [email protected] wrote:
In short:
Using Bokeh Server, I can add and delete box annotations no problem prior to the plot being displayed using some helper functions. However, once the plot is displayed to the user, I can add box annotations with call-backs, but can not delete the box annotations using callback buttons and the exact same helper functions. If it was a scope issue, I would expect add and delete to either both work, or both not work.
In detail:
To see what I mean, go to line 138 where the debugging code starts in the attached python file and follow the instructions for Debug 1,2,3,4 which are repeated here for clarity
It appears as if although the box annotations are added and they can be found immediately after adding while still within the scope of the add_box_annotations() function as seen by the output produced to standard out from line 65. However, immediately after exiting that function, the box annotations can no longer be found in the same figure object “f” as seen by the lack of output provided to standard out from the add_box_annotations_handler() function in line 96.
#======================
initialize the layout
f = draw_plot3()
Debug 1:
uncommenting the following results in the expected behavior of box annotations
being added to the plot when the plot is first displayed to the user.
#add_box_annotations(f)
Debug 2:
uncommenting the previous along with following results in the expected behavior
of the box annotations being removed prior to the plot being displayed to the
user for the first time.
#clear_box_annotations(f)
Debug 3:
clicking on the “add” button results in the expected behavior of box annotations
being added.
Debug 4:
clicking on the “delete” button (with an annotation displayed) results in the