Bokeh 导入 json_item 在 Jupyter 中序列化 JSON

Bokeh import json_item serialized JSON in Jupyter

Cross-post 在 Bokeh 论坛上:https://discourse.bokeh.org/t/display-json-item-serialized-json-in-jupyter-notebook/7245/3

我已使用 bokeh.embed.json_item 将散景图序列化为 json,如文档中所述:https://docs.bokeh.org/en/latest/docs/reference/embed.html#bokeh.embed.json_item

我现在想在 Python(Jupyter 笔记本)中再次加载它。我该怎么做?该文档仅提到使用 JavaScript 加载它并将其嵌入网页:https://docs.bokeh.org/en/latest/docs/user_guide/embed.html

一种方法是在 IPython 笔记本中显示一个 HTML 对象,如下所示:

from IPython.core.display import display, HTML
html_plot = f'''
<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js"
        crossorigin="anonymous"></script>
</head>
<body>
  <div id="myplot"></div>
  <script>
  item = {plot_json}
  Bokeh.embed.embed_item(item, "myplot");
  </script>
</body>
'''
display(HTML(html_plot))

但是,这并没有让我恢复我可以操纵的散景 Figure 对象。

从 Bokeh 2.3 开始,将导出的 JSON 重新摄取回 Python 仍然是 open issue