Ipywidgets与谷歌Colaboratory

时间:2017-11-13 16:33:18

标签: jupyter-notebook ipywidgets google-colaboratory

我正在尝试将ipywidgets与Google Colaboratory一起使用,并且(与plotly一样)最简单的example from the docs不起作用。下面的代码显示了本地笔记本中的滑块,但只在Google笔记本中返回10和<function __main__.f>

!pip install ipywidgets

from ipywidgets import interact

def f(x):
  return x

interact(f, x=10)

我是否可以使用其他自定义初始化来启用小部件?

4 个答案:

答案 0 :(得分:9)

ipywidgets目前不与Colab合作:我们有一个不同的安全模型,其中每个输出都在自己的iframe中(与主Colab页面的起源不同)。这可以防止ipywidgets按当前的方式工作。

答案 1 :(得分:2)

我认为Ipywidgets现在正在与Google合作实验室合作。我测试了一些装饰器并顺利运行。

您的代码已导致:

enter image description here

答案 2 :(得分:1)

!pip install ipywidgets

# this will allow the notebook to reload/refresh automatically within the runtime
%reload_ext autoreload
%autoreload 2

from ipywidgets import interact

def f(x):
  return x

interact(f, x=10)

答案 3 :(得分:0)

ipywidgets现已在colab中得到支持; ipywidgets.Image是一个明显的例外。参见https://github.com/googlecolab/colabtools/issues/587