Python 与JupyterHub中的Bokeh服务器交互

Python 与JupyterHub中的Bokeh服务器交互,python,bokeh,jupyterhub,Python,Bokeh,Jupyterhub,我有一个可以捕获用户绘制的坐标的工具,它在Jupyter中工作得很好: import numpy as np N = 500 x = np.linspace(0, 3, N) y = np.linspace(0, 3, N) xx, yy = np.meshgrid(x, y) z = np.sin(xx) * np.cos(yy) from bokeh import events from bokeh.io import show, output_notebook from bokeh.

我有一个可以捕获用户绘制的坐标的工具,它在Jupyter中工作得很好:

import numpy as np

N = 500
x = np.linspace(0, 3, N)
y = np.linspace(0, 3, N)

xx, yy = np.meshgrid(x, y)
z = np.sin(xx) * np.cos(yy)

from bokeh import events
from bokeh.io import show, output_notebook
from bokeh.plotting import figure

output_notebook()

geom = {}
global geom

def print_event(attributes=[]):
    def python_callback(event):
        geom.update(event.__dict__['geometry'])
    return python_callback

def modify_doc(doc):
    p = figure(x_range=(0, 3), y_range=(0, 3), 
      tools='reset,box_select,lasso_select,poly_select', plot_height=300)
    p.image(image=[z], x=0, y=0, dw=3, dh=3, palette='Spectral11')
    p.on_event(events.SelectionGeometry, print_event(attributes=['geometry']))
    doc.add_root(p)

show(modify_doc)

print(geom)

但是在JupyterHub中,
显示(modify_doc)
不会生成绘图,开发人员控制台显示JS无法从该请求加载响应数据:

http://localhost:43474/autoload.js?bokeh-autoload-element=111c97fa-dbc8-437c-9770-471dc23fb13f&bokeh-absolute-url=http://localhost:43474&resources=none
因为我在我的jupyterhub上访问了Dask仪表板

我想也许像这样的事情可以奏效:

show(modify_doc, notebook_url='pangeo.esipfed.org/user/rsignell-usgs/proxy')
但这产生了这个URL:

http://pangeo.esipfed.org/user/rsignell-usgs/proxy:34560/autoload.js?bokeh-autoload-element=870004ec-7366-4b38-b20f-2119e2b52327&bokeh-app-path=/user/rsignell-usgs/proxy:34560&bokeh-absolute-url=http://pangeo.esipfed.org/user/rsignell-usgs/proxy:34560&resources=none
这产生了一个
404
错误

我知道几个月前就有这样一种交互方式,我想我应该能够指定
notebook\u url
作为一个函数来实现这一功能,但我想不出来


是否清楚我做错了什么,或者是否有人有这样一个例子

Bokeh的文档中提到了在通过jupyterhub代理时与Bokeh服务器交互所需的一些设置:


希望这能有所帮助。

您能提供更多详细信息吗?我正在使用Jupyterhub和Kubespawner。如何传递示例中提到的
EXTERNAL_URL
env变量?