curdoc().add_root() 导致散景图渲染无提示地失败
curdoc().add_root() causes bokeh plot rendering to fail silently
下面的散景应用程序旨在在按下按钮时生成随机数据集。我正在尝试使用 bokeh.client
样式为应用程序提供服务,其中有一个会话可以在同时查看者之间共享。
如果我包含以下行:curdoc().add_root(column(p,button))
该图将不会出现在浏览器中。我在 JS 控制台中得到一个包含快乐消息的空白页面。如果我删除它,我会得到一个静态图,没有按钮。谁能解释一下我的方法有什么问题吗?
我应该补充一点,该应用程序在具有多个不同会话的其他服务器样式中工作。我在那里调用 bokeh serve myapp.py
并且不调用 session
对象。
import numpy as np
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import Button
from bokeh.client import push_session, pull_session
points = 100*np.random.rand(3,100)
points_x = points[0].tolist()
points_y = points[1].tolist()
p = figure(x_range=(0,100), y_range=(0,100))
circle_p = p.circle(x = points_x,
y = points_y,
size = 20,
color = "navy",
alpha = 0.5)
ds = circle_p.data_source
#callback function to update circles
def button_callback():
new_data = dict()
new_points = 100*np.random.rand(3,100)
new_data['x'] = new_points[0].tolist()
new_data['y'] = new_points[1].tolist()
new_data['z'] = new_points[2].tolist()
ds.data = new_data
#Add the button widget thingie to trigger the update
button = Button(label="Update")
button.on_click(button_callback)
# Put the button and plot in a layout in document
curdoc().add_root(column(p,button))
#create a session
session = push_session(curdoc())
session.show(p)
session.loop_until_closed()
你只要
session.show()
不是
session.show(p)
因为您想显示整个文档,而不仅仅是情节。第一个版本适用于 Bokeh 0.12.6
(后者也适用,但情节重复了两次。我猜你使用的是旧版本,也有一些布局错误)
下面的散景应用程序旨在在按下按钮时生成随机数据集。我正在尝试使用 bokeh.client
样式为应用程序提供服务,其中有一个会话可以在同时查看者之间共享。
如果我包含以下行:curdoc().add_root(column(p,button))
该图将不会出现在浏览器中。我在 JS 控制台中得到一个包含快乐消息的空白页面。如果我删除它,我会得到一个静态图,没有按钮。谁能解释一下我的方法有什么问题吗?
我应该补充一点,该应用程序在具有多个不同会话的其他服务器样式中工作。我在那里调用 bokeh serve myapp.py
并且不调用 session
对象。
import numpy as np
from bokeh.plotting import figure, curdoc
from bokeh.layouts import column
from bokeh.models import Button
from bokeh.client import push_session, pull_session
points = 100*np.random.rand(3,100)
points_x = points[0].tolist()
points_y = points[1].tolist()
p = figure(x_range=(0,100), y_range=(0,100))
circle_p = p.circle(x = points_x,
y = points_y,
size = 20,
color = "navy",
alpha = 0.5)
ds = circle_p.data_source
#callback function to update circles
def button_callback():
new_data = dict()
new_points = 100*np.random.rand(3,100)
new_data['x'] = new_points[0].tolist()
new_data['y'] = new_points[1].tolist()
new_data['z'] = new_points[2].tolist()
ds.data = new_data
#Add the button widget thingie to trigger the update
button = Button(label="Update")
button.on_click(button_callback)
# Put the button and plot in a layout in document
curdoc().add_root(column(p,button))
#create a session
session = push_session(curdoc())
session.show(p)
session.loop_until_closed()
你只要
session.show()
不是
session.show(p)
因为您想显示整个文档,而不仅仅是情节。第一个版本适用于 Bokeh 0.12.6
(后者也适用,但情节重复了两次。我猜你使用的是旧版本,也有一些布局错误)