You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS SageMaker Notebook中Panel Tabulator的on_edit事件失效求助

问题

在AWS SageMaker Notebook(Jupyter Lab)中实现Panel Tabulator的on_edit事件时遇到异常:表格可正常渲染、单元格可编辑,但编辑完成后on_edit绑定的回调函数完全不触发(无打印输出,tabulator.value也始终是原始数据)。相同代码在Panelite环境中可正常工作,能在开发者控制台看到回调日志,但在SageMaker中无任何反应。

代码示例

import panel as pn
import pandas as pd

pn.extension('tabulator')

df = pd.DataFrame({
    'Name': ['John', 'Jane', 'Bob', 'Alice'],
    'Age': [30, 25, 35, 28],
    'City': ['New York', 'London', 'Paris', 'Tokyo']
})

tabulator = pn.widgets.Tabulator(df)
tabulator.on_edit(lambda e: print(e.column, e.row, e.old, e.value))

pn.Column(tabulator).servable()

环境信息

SageMaker Notebook的JupyterLab扩展列表:

JupyterLab v4.2.1
/home/ec2-user/anaconda3/envs/python3/share/jupyter/labextensions
        jupyterlab_pygments v0.3.0 enabled OK (python, jupyterlab_pygments)
        jupyterlab-plotly v5.22.0 enabled  X
        @jupyter-widgets/jupyterlab-manager v5.0.11 enabled OK (python, jupyterlab_widgets)
        @jupyter-notebook/lab-extension v7.2.0 enabled OK
        @pyviz/jupyterlab_pyviz v3.0.3 enabled OK


   The following extensions may be outdated or specify dependencies that are incompatible with the current version of jupyterlab:
        jupyterlab-plotly
        
   If you are a user, check if an update is available for these packages.
   If you are a developer, re-run with `--verbose` flag for more details.

解决方案

1. 升级Panel版本

SageMaker默认预装的Panel版本可能与JupyterLab 4.x存在兼容性问题,执行以下命令升级到最新稳定版:

pip install --upgrade panel

升级完成后重启JupyterLab,确保@pyviz/jupyterlab_pyviz扩展与Panel版本匹配。

2. 使用Panel服务器模式运行

在SageMaker Notebook中,直接渲染Panel组件可能无法触发回调,改用Panel服务器模式:

  • 修改代码末尾为:
pn.serve(pn.Column(tabulator), port=5006, show=False)
  • 通过SageMaker的端口转发功能,将本地5006端口映射到实例的5006端口,在浏览器中访问对应URL即可正常触发on_edit事件。

3. 移除冲突扩展

禁用标记为异常的jupyterlab-plotly扩展,避免环境冲突:

jupyter labextension disable jupyterlab-plotly

重启JupyterLab后测试回调功能。

4. 替代AWS托管环境

若以上方法无效,可尝试以下AWS托管方案:

  • AWS CodeWhisperer Studio:交互式Python环境对Panel组件的回调支持更完善。
  • 自定义EC2 JupyterLab实例:完全控制环境依赖,可按需安装最新版Panel及兼容扩展。

内容的提问来源于stack exchange,提问作者Reini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 07:23:12