The below code makes it seem like the callable passed to a DynamicMap can not change the Element type. When changing the category widget to B
a Curve
element is returned instead of Points
, but the plot is just empty. Is this behavior not supported or is there some opts
magic that is required to make it work?
import holoviews as hv
import numpy as np
import panel as pn
hv.extension('bokeh')
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
main_category_widget = pn.widgets.Select(name='Main category', options=['A','B'], value='A')
widgets = main_category_widget
@pn.depends(selected_main_category=main_category_widget.param.value)
def get_points(selected_main_category):
if selected_main_category == 'A':
return hv.Points(np.random.rand(5,5)).opts(size=10, title='Points')
else:
return hv.Curve(np.random.rand(5,5)).opts(title='Curve')
points = hv.DynamicMap(get_points).opts(height=400, width=800)
pn.Row(widgets, points)
Using
hv.Overlay
as return type ofget_points()
your code is working as expected: