问题描述
我从另一篇文章中复制了下面的代码,该文章是关于创建小部件的,这些小部件根据选择来更新绘图:
# import libraries
import numpy as np
import pandas as pd
import hvplot
import hvplot.pandas
import holoviews as hv
hv.extension('bokeh',logo=False)
import panel as pn
# create sample data
df = pd.DataFrame({
'col1': np.random.rand(30),'col2': np.random.normal(size=30),'category_col': np.random.choice(['category1','category2'],size=30)
})
# create widget to select category
category = pn.widgets.Select(options=['category1','category2'])
# function that returns a plot depending on the category selected
@pn.depends(category)
def get_plot(category):
df_selected = df[df['category_col'] == category]
plot = df_selected.hvplot.scatter(x='col1',y='col2')
return plot
# show dashboard with selection widget and dynamic plot
pn.Column(
pn.Row(category),get_plot,)
# get value of current selected category
category.value
但是,对我来说,选择后图表不会更新。有人知道这是怎么回事吗?我正在尝试在本地计算机(没有服务器)的Jupyter Lab笔记本中执行此操作。我正在运行这些库的以下版本:
holoviews:1.13.3 hvplot:0.6.0 面板:0.9.7
任何见识将不胜感激!
亲切的问候
解决方法
对于使用相同版本的经典笔记本,该代码对我来说效果很好(holoviews:1.13.3 hvplot:0.6.0面板:0.9.7)。您是否安装了JupyterLab扩展程序? https://panel.holoviz.org/#installation