【问题标题】:push_notebook does not work in Google Collab Jupyter Notebook推送笔记本在 Google Colab Jupyter Notebook 中不起作用
【发布时间】:2020-07-20 00:27:49
【问题描述】:

我在 Google 协作中使用散景。我想知道是否有人在 Google Collab Jupyter notebook 中使用过 push_notebook。我正在尝试在 Google Collab 上的 Jupiter Notebook 中运行以下代码,但它卡在 push_notebook() 命令上

from ipywidgets import interact
import numpy as np
from bokeh.io import push_notebook,show,output_notebook
from bokeh.plotting import figure
output_notebook()

x=np.linspace(0,2*np.pi,2000)
y=np.sin(x)
p=figure(title="ff",plot_height=300,plot_width=600,y_range=(-5,5))
r=p.line(x,y,color="red",line_width=2)
def update(f,w=1,A=1,phi=0):
   print("fff")
   if f== "sin":func=np.sin
   if f== "sin":func=np.sin
   elif f=="cos":func =np.cos
   elif f== "tan":func=np.tan
   r.data_source.data['y']=A*func(w*x+phi) 
   push_notebook()
show(p,notebook_handle=True)
interact(update,f=["sin","cos","tan"],w=(0,100),A=(1,5),phi=(0,20,0.1))

任何人都可以建议代码中有什么问题以及如何运行 Google Collab。

【问题讨论】:

    标签: jupyter-notebook slider bokeh google-colaboratory ipywidgets


    【解决方案1】:

    push_notebook 不能也不能在 Google Collab 上工作,因为 Google 的笔记本实现不允许打开必要的 websocket 连接。除非/除非谷歌最终做出改变,否则对此无能为力。

    参考:https://github.com/bokeh/bokeh/issues/9302

    【讨论】:

    • thnx 在那种情况下你能不能评论一下如何使用散景控制,例如在这种情况下我想改变滑块控件上的图形,
    • 我认为目前在 Collab 中是不可能的。显然,他们正在努力更新 Google 方面的内容(请参阅链接问题中的最新 cmets),因此对未来有一些希望。但在他们做出更改之前,我们会发布更新版本以使用这些更改,这些功能只能在经典笔记本和 JupyterLab 中得到支持。您可以做的最好的事情是show 每次滑块更新时都会生成一个全新的绘图。不过,不确定这是否可行。
    猜你喜欢
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2020-09-28
    • 2019-02-28
    • 1970-01-01
    • 2018-09-01
    相关资源
    最近更新 更多