I have the next application my_app.py:
import numpy as np
import holoviews as hv
from bokeh.io import curdoc
from bokeh.layouts import layout
from bokeh.models import HoverTool
hv.extension(‘bokeh’)
renderer = hv.renderer(‘bokeh’).instance(mode=‘server’)
frequencies = [0.5, 1.0]
def sine_curve(phase, freq):
xvals = [0.1* i for i in range(100)]
return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))
def callback1():
print(‘Curve “0.5” is turn off’)
def callback2():
print(‘Curve “0.5” is turn on’)
curve_dict = {f:sine_curve(0,f) for f in frequencies}
ndoverlay = hv.NdOverlay(curve_dict, kdims=‘frequency’)
doc=curdoc()
hvplot = renderer.get_plot(ndoverlay, doc)
plot=layout(hvplot.state)
doc.add_root(plot)
I need to make sure that when you turn off the curve “0.5” in the legend, the callback1 () function is called, and when you turn on the curve “0.5” callback2 () function is called.
How to implement this?



Here’s my solution - a bit more generic and removes the unnecessary call to 