在 Google Cloud Datalab 中执行 IPyWidgets

Execute IPyWidgets in Google Cloud Datalab

对于一个项目,我们尝试使用 IPyWidgets 扩展 Google Cloud Datalab。当我们在本地的 jupyter 笔记本(而不是 google-cloud-datalab)中尝试 IPyWidgets 时,一切 运行 都如预期的那样(即我们尝试显示一个文本字段,它起作用了)。当我们尝试在 Google Cloud Datalab 中执行相同的代码时,它失败了。在 Web 控制台中,我们看到以下错误:

错误 1:

Error message: "Class ipython.widget not found in registry "
Error stack: "load_class/<@http://localhost:8081/static/notebook/js/main.min.js:12751:28load_class@http://localhost:8081/static/notebook/js/main.min.js:12736:1CommManager.prototype.comm_open@http://localhost:8081/static/notebook/js/main.min.js:21802:31.proxy/i@http://localhost:8081/static/notebook/js/main.min.js:89:5486Kernel.prototype._handle_iopub_message@http://localhost:8081/static/notebook/js/main.min.js:23101:20Kernel.prototype._finish_ws_message@http://localhost:8081/static/notebook/js/main.min.js:22936:1Kernel.prototype._handle_ws_message/this._msg_queue<@http://localhost:8081/static/notebook/js/main.min.js:22926:39"

错误 2:

Message: Could not open comm
Error message: "Couldn't process kernel message"
Error stack: "WrappedError@http://localhost:8081/static/notebook/js/main.min.js:12706:19reject/<@http://localhost:8081/static/notebook/js/main.min.js:12785:33"

奇怪的是,当 google-cloud-datalab 处于 运行ning 状态时,我们转到 jupyter notebook(在端口 9000 上),然后执行那里的代码,它可以正常工作.

我们是否需要对 nb.html、and/or static.ts 进行更改才能使其生效?

问题:有没有办法在Google Cloud Datalab上执行IPyWidgets?

你好,布莱希特

编辑: 我现在可以从 google-cloud-datalab 中的 IPyWidgets 加载 js 和 css 文件(您需要更改 static.ts,对于那些想知道的人)。唯一剩下的问题(希望如此)是我们收到以下错误:

"Error: Could not determine where the display message was from. Widget will not be displayed".

这是因为

var cell = this.get_msg_cell(msg.parent_header.msg_id);

为空(ipywidgets/widgets/js/manager.js 的第 556 行)。我假设更改 static.ts 还不够?

那个:

"Error: Could not determine where the display message was from.  Widget will not be displayed".

可以通过更改 datalab.js 中的这一行来解决问题:

originalExecute.apply(this, [ code, callbacks, options ]);

至:

return originalExecute.apply(this, [ code, callbacks, options ]);