启用jupyter小部件

时间:2018-04-11 07:59:23

标签: python jupyter-notebook jupyter

jupyter widgets exension不呈现ui项目。尝试更新客户端并启用widgetsnbextension但代码如下:

!pip install --upgrade jupyter_core jupyter_client
!jupyter nbextension enable --py widgetsnbextension

from IPython.display import display
button = widgets.Button(description="Click Me!")
display(button)

def on_button_clicked(b):
    print("Button clicked.")

button.on_click(on_button_clicked)

呈现:

Requirement already up-to-date: jupyter_core in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: jupyter_client in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: traitlets in /usr/local/lib/python2.7/dist-packages (from jupyter_core)
Requirement already up-to-date: python-dateutil>=2.1 in /usr/local/lib/python2.7/dist-packages (from jupyter_client)
Requirement already up-to-date: pyzmq>=13 in /usr/local/lib/python2.7/dist-packages (from jupyter_client)
Requirement already up-to-date: tornado>=4.1 in /usr/local/lib/python2.7/dist-packages (from jupyter_client)
Requirement already up-to-date: enum34; python_version == "2.7" in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: six in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: decorator in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: ipython-genutils in /usr/local/lib/python2.7/dist-packages (from traitlets->jupyter_core)
Requirement already up-to-date: singledispatch in /usr/local/lib/python2.7/dist-packages (from tornado>=4.1->jupyter_client)
Requirement already up-to-date: futures in /usr/local/lib/python2.7/dist-packages (from tornado>=4.1->jupyter_client)
Requirement already up-to-date: backports-abc>=0.4 in /usr/local/lib/python2.7/dist-packages (from tornado>=4.1->jupyter_client)
Enabling notebook extension jupyter-js-widgets/extension...
      - Validating: OK
Button(description='Click Me!', style=ButtonStyle())

案文:

Button(description='Click Me!', style=ButtonStyle())
呈现

而不是UI按钮

是否需要另一个图书馆?

2 个答案:

答案 0 :(得分:0)

来自http://ipywidgets.readthedocs.io/en/latest/user_install.html

  

问题:当我显示小部件或进行交互时,我只看到一些文字,   例如IntSlider(value = 0)或interactive(children =(IntSlider(value = 0,   description ='x',max = 1),Output()),   _dom_classes =( '插件-相互作用',))。有什么问题?

     

答案:如果小部件打印小部件的文本表示   控制不可用。这可能意味着小部件JavaScript仍然存在   加载。如果消息仍存在于Jupyter笔记本中或   JupyterLab,它可能意味着小部件JavaScript库是   要么未安装,要么未启用。请参阅安装说明   以上是设置说明。

页面刷新修复了我的问题。我认为我的问题中提到的安装仍然是必需的。

答案 1 :(得分:0)

就我而言,我不得不再次运行jupyter笔记本中的单元格。在小部件标签中,选择 Save Notebook Widgets State (保存笔记本小部件状态)可以在每次再次打开笔记本时呈现小部件,而不必重新运行它。