在Jupyter笔记本中使用交互元素更新散景



我正在尝试使用jupyter窗口小部件在bokeh中进行跨度。

from ipywidgets import interact
import numpy as np
from scipy.stats import norm
from bokeh.sampledata.daylight import daylight_warsaw_2013
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Span
output_notebook()
p = figure()
x_axis = np.arange(-10, 10, 0.001)
# Mean = 0, SD = 2.
y_axis = norm.pdf(x_axis,0,2)
p.line(x_axis, y_axis, line_dash='solid', line_width=2)
cutoff = Span(location=1,
              dimension='height', line_color='green',
              line_dash='dashed', line_width=2)
p.add_layout(cutoff)
show(p, notebook_handle=True)
def update(new_cutoff_location):
    cutoff.location = new_cutoff_location
    push_notebook()
interact(update, new_cutoff_location = 1.0)

运行此代码时,我会在push_notebook()上获得ValueError: PATCH-DOC message requires at least one event。我怀疑这表明未检测到cutoff.location的更新,因此看起来似乎没有更改。通过手柄似乎没有什么不同。查看此GitHub问题中的示例代码,看起来跨度元素上曾经有一个set方法,但是我的跨度元素cutoff似乎没有一个。也许我应该打电话来注册更改?

我在bokeh 0.12.11上使用jupyter 1.0.0,jupyter-client 5.1.0,jupyter-console 5.2.0,jupyter-core 4.4.0

这似乎是bokeh 0.12.11中的回归。您的代码可与版本0.12.10一起使用,因此即时解决方法是降级。我在这里提出了您可以遵循的GitHub问题。我们将尽快发布新的点发布。

更新:该问题现在已在Bokeh的最新版本中解决

最新更新