在参数化 class(holoviz 参数面板)中使用参数时获取不同的(非默认)小部件

Get a different (non default) widget when using param in parameterized class (holoviz param panel)

我使用参数化 class 来构建我的 Panel 仪表板。

我想使用 CrossSelector but this selector does not seem to be available when looking at the options that library Param gives. It only seems to have a ListSelector

如何使用参数获取此 CrossSelector?

import param
import panel as pn

pn.extension()

class ValveExplorer(param.Parameterized):

    selected_features = param.ListSelector(
        default=[1, 3],
        objects=[1, 2, 3, 4],
    )

valve_explorer = ValveExplorer()  

# show list selector
pn.Row(valve_explorer.param['selected_features'])

这会产生以下默认的 ListSelector,但我不想要这个。我想改用 CrossSelector:

Param 为每个选择器都有一个默认小部件,但您可以更改它。

您可以使用 pn.Param():

覆盖此默认小部件,如下所示以在您的示例中获取 CrossSelector
pn.Row(pn.Param(
    valve_explorer.param['selected_features'], 
    widgets={'selected_features': pn.widgets.CrossSelector}
))


正在使用 pn.panel():

pn.Row(pn.panel(
    valve_explorer.param['selected_features'], 
    widgets={'selected_features': pn.widgets.CrossSelector}
))


在此处查看有关将 Param 与 Panel 结合使用的更多文档:
https://panel.pyviz.org/user_guide/Param.html