我正在尝试将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)
我是否可以使用其他自定义初始化来启用小部件?
答案 0 :(得分:9)
ipywidgets
目前不与Colab合作:我们有一个不同的安全模型,其中每个输出都在自己的iframe中(与主Colab页面的起源不同)。这可以防止ipywidgets按当前的方式工作。
答案 1 :(得分:2)
答案 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。