DynamicMap可调用对象是否总是必须返回相同的类型?

时间:2019-12-03 04:34:04

标签: python holoviews pyviz

以下代码使传递给DynamicMap的callable似乎无法更改Element类型。将类别窗口小部件更改为B时,将返回Curve元素而不是Points,但是该图只是空白。是否支持此行为,或者需要某种opts魔术才能使其正常工作?

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)

1 个答案:

答案 0 :(得分:1)

使用/app作为hv.Overlay的返回类型,您的代码将按预期工作:

get_points()