Repository: bokeh/bokeh

Issue:
hide annotations via callback
# Original question
I have a Bokeh plot where I add some data in the form of a `LabelSet` and `BoxAnnotation` as overlay, but I want to be able to dynamically enable/disable this overlay.

I can enable/hide some of the lines in the plot [already](http://stackoverflow.com/q/40592165/1562285), but the system for the Annotations seems to be different. I've got so far already

## Initialising

    from ipywidgets import interact
    from bokeh.plotting import figure as bf
    from bokeh.layouts import layout as bl
    from bokeh.models import Toggle, BoxAnnotation, CustomJS
    from bokeh.io import push_notebook, show, output_notebook
    output_notebook()

## Widget generation

    p = bf(title='test', x_range=(0,1), y_range=(0,1))
    x = [1/3, 2/3]
    y=[1/3, 2/3]
    p.circle(x=x, y=y, size=15)
    
    box = BoxAnnotation(left=None, right=0.5, fill_color='red', fill_alpha=0.1)
    
    p.add_layout(box)

## Interactivity

    code = '''\
    if toggle.active
        box.visible = true
        console.log 'enabling box'
    else
        box.visible = false
        console.log 'disabling box'
    '''
    callback = CustomJS.from_coffeescript(code=code, args={})
    toggle = Toggle(label="Red Box", button_type="success", callback=callback)
    callback.args = {'toggle': toggle, 'box': box}
    
    layout = bl([p], [toggle])
    show(layout)

When I check the JS console, the if/else clauses get triggered as expected, so the `Toggle` works but the red box stays in place, both in Firefox as in IE.;
When I try with a `Labelset` instead of a `BoxAnnotation` it doesn't hide either.

 ### Bokeh info
Python version      :  3.5.2 |Anaconda custom (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
IPython version     :  5.1.0
Bokeh version       :  0.12.3
BokehJS static path :  C:\Anaconda3\lib\site-packages\bokeh\server\static

the notebook can be found at [My github repo](https://github.com/vadella/StackOverflow-questions/blob/master/bokeh_glyph.ipynb)

# Preliminary answer
This is a copy of [a StackOverflow question](http://stackoverflow.com/q/40849500/1562285) where @bryevdv [answered](http://stackoverflow.com/a/40852280/1562285)  there might be some plumbing that is not hooked up on the BokehJS side to respond to `visible` and asked me to repeat the question here.

As a workaround he suggested to use alpha settings for the time being, which works, both on the `LabelSet` as on the `BoxAnnotation`


Discussion:
@mattpap, I just got the following console error trying to run the "working code" in the notebook above:

```
Uncaught ReferenceError: exports is not defined
    at r.eval (eval at <anonymous> (bokeh-0.12.5dev14.min.js:30), <anonymous>:4:23)
    at r.CustomJS.r.execute (bokeh-0.12.5dev14.min.js:30)
    at t.i.AbstractButtonView.t.change_input (bokeh-widgets-0.12.5dev14.min.js:1)
    at t.i.ToggleView.t.change_input (bokeh-widgets-0.12.5dev14.min.js:3)
    at HTMLDivElement.dispatch (bokeh-widgets-0.12.5dev14.min.js:181)
    at HTMLDivElement.o.dispatch (bokeh-widgets-0.12.5dev14.min.js:203)
    at HTMLDivElement.g.handle (bokeh-widgets-0.12.5dev14.min.js:180)

Resolving patch:
diff --git a/sphinx/source/docs/user_guide/examples/styling_visible_annotation_with_interaction.py b/sphinx/source/docs/user_guide/examples/styling_visible_annotation_with_interaction.py
new file mode 100644
--- /dev/null
+++ b/sphinx/source/docs/user_guide/examples/styling_visible_annotation_with_interaction.py
@@ -0,0 +1,29 @@
+from bokeh.io import output_file, show
+from bokeh.plotting import figure
+from bokeh.layouts import layout
+from bokeh.models import Toggle, BoxAnnotation, CustomJS
+
+# We set-up the same standard figure with two lines and now a box over top
+p = figure(plot_width=600, plot_height=200, tools='')
+visible_line = p.line([1, 2, 3], [1, 2, 1], line_color="blue")
+invisible_line = p.line([1, 2, 3], [2, 1, 2], line_color="pink")
+
+box = BoxAnnotation(left=1.5, right=2.5, fill_color='green', fill_alpha=0.1)
+p.add_layout(box)
+
+# We write coffeescript to link toggle with visible property of box and line
+code = '''\
+object.visible = toggle.active
+'''
+
+callback1 = CustomJS.from_coffeescript(code=code, args={})
+toggle1 = Toggle(label="Green Box", button_type="success", callback=callback1)
+callback1.args = {'toggle': toggle1, 'object': box}
+
+callback2 = CustomJS.from_coffeescript(code=code, args={})
+toggle2 = Toggle(label="Pink Line", button_type="success", callback=callback2)
+callback2.args = {'toggle': toggle2, 'object': invisible_line}
+
+output_file("styling_visible_annotation_with_interaction.html")
+
+show(layout([p], [toggle1, toggle2]))


Test patch: