from ipywidgets import interact
import numpy as np

from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
output_notebook()

x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)

p = figure(title="simple bar example", plot_height=300, plot_width=800)
#r = p.line(x, y, color="#2222aa", line_width=3)
r = p.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1,2,3], color="#CAB2D6")

def update(f, w=1, A=1, phi=0):
    if   f == "sin": func = np.sin
    elif f == "cos": func = np.cos
    elif f == "tan": func = np.tan
    r.data_source.data['top'] = [1, 2, 10 * A * func(w * x + phi)]
    push_notebook()

show(p, notebook_handle=True)

#interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))
update(f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))
Loading BokehJS ...
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-24-9e7699291d36> in <module>()
     23 
     24 #interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))
---> 25 update(f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))

<ipython-input-24-9e7699291d36> in update(f, w, A, phi)
     17     elif f == "cos": func = np.cos
     18     elif f == "tan": func = np.tan
---> 19     r.data_source.data['top'] = [1, 2, 10 * A * func(w * x + phi)]
     20     push_notebook()
     21 

UnboundLocalError: local variable 'func' referenced before assignment