首页 > 解决方案 > Panel + Param 自定义 MultiFileSelector 小部件

问题描述

我尝试将 MultiFileSelector 参数转换为可以交互的小部件,但失败了。在本教程中,我尝试了以下方法。

class CustomExample(param.Parameterized):
    f = param.MultiFileSelector()

pn.Param(CustomExample.param, widgets={ 'f': pn.widgets.Multiselect})

但我得到了错误,

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-bb344c131fb8> in <module>
      5     #select_number = param.Selector(objects=[0, 1, 10, 100])
      6 
----> 7 pn.Param(CustomExample.param, widgets={ 'f': pn.widgets.Multiselect})

AttributeError: module 'panel.widgets' has no attribute 'Multiselect'

任何指针都会很棒。

标签: parameterspanepanel-pyviz

解决方案


由于您使用的是param,因此在这种情况下,您必须检查哪个参数最接近您正在寻找的参数 param.MultiFileSelector:

class CustomExample(param.Parameterized):
    file_selector = param.MultiFileSelector(path='*')

pn.Param(CustomExample.param['file_selector'])

这将显示以下多文件选择器: 如果要更改为不同的非默认选择器,可以这样做:带有参数 pyviz 的标准多文件选择器

class CustomExample(param.Parameterized):
    file_selector = param.MultiFileSelector(path='*')

pn.Param(
    CustomExample.param['file_selector'], 
    widgets={'file_selector': pn.widgets.CrossSelector},
))

结果选择器: 您已经找到了这个文档: http: //panel.holoviz.org/user_guide/Param.html 但也许也看看这些 SO-questions:Get a different (non default) widget when using param in parameterized class (holoviz 参数面板)在 hvplot/holoviews/panel 对象中更改小部件类型的最佳方法是什么?使用面板交叉选择器覆盖默认的多文件选择器










推荐阅读