python - 在 JupyterHub 中与 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)
但是在 JupyterHubshow(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 仪表板
http://pangeo.esipfed.org/user/rsignell-usgs/proxy/8787
我虽然也许这样的事情可以工作:
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
错误。
我看到几个月前有一个Bokeh 增强应该允许这种交互工作,我认为我应该能够指定notebook_url
一个函数来完成这项工作,但我无法弄清楚。
是否清楚我做错了什么,或者有人有一个例子说明这是如何工作的?
解决方案
Bokeh 的文档提到了一些设置,当通过 jupyterhub 代理时,您需要做一些设置来与 bokeh 服务器交互:
https://docs.bokeh.org/en/latest/docs/user_guide/notebook.html#jupyterhub
希望这会有所帮助。
推荐阅读
- c++ - strcpy(s+i, s+i+1) 是什么意思?
- java - 如何通过 Mongock 向集合中的所有文档添加新字段?
- swift - 如何从 AES.GCM.Nonce 获取数据 obj - swift
- ios - NSArray 结构数组中的重复数组(Swift)
- python - pytest:是否可以从代码中启用标记?
- vue.js - Nuxt.JS 创建自定义 UI 材质组件
- android - 如何更改 PagingSource 或 RemoteMediator 中的 Paging3 问题
- c++ - VS Code:在 browse.path 中找不到包含文件,但 IDE 在我键入时识别出该名称
- c# - 是否可以在 Web App Bot 中翻译自适应卡片?
- python - 检测在一段时间内按下的键 Python