在 reveal.js 中嵌入本地 html 文件

Embed a local html file in reveal.js

我想导入 bokeh interactive graphs in my reveal.js 演示文稿。

我能做什么

  1. 我可以使用 iframe 在 reveal.js 中嵌入 html 内容:
<iframe data-src="https://demo.bokeh.org/sliders" 
width="445" height="355" frameborder="0" marginwidth="0" marginheight="0" 
scrolling="no" style="border:3px solid #666; margin-bottom:5px; max-width:
100%;" allowfullscreen=""></iframe>
  1. 我可以将散景图保存为 html 格式:
from bokeh.plotting import figure, output_file, show

output_file("/line.html")
p = figure(plot_width=400, plot_height=400)
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
show(p)

这会生成一个文件 line.html,当我用我的网络浏览器打开它时,我可以看到它并与之交互。

我不能做什么

将我的 line.html 文件嵌入 reveal.js.

我试过了:

  1. <iframe data-src="/Users/JohnDoe/line.html" width="945" height="555" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:3px solid #666; margin-bottom:5px; max-width: 600%;" allowfullscreen=""></iframe>

    这导致消息 Cannot GET /Users/JohnDoe/line.html 显示在我的 iframe 中。

  2. <iframe data-src="file:///Users/JohnDoe/line.html" width="945" height="555" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:3px solid #666; margin-bottom:5px; max-width: 600%;" allowfullscreen=""></iframe>

    Trame 中没有显示任何内容。

我想做什么

我希望我的 .html 文件显示在我的 iframe 中,因为它在“我能做什么”部分的 1. 中工作。

Reveal.js 输出是从某种本地服务器显示的,对吗?在这种情况下,AFAIK IFrame 不允许您从本地文件加载。通常,您不能从 http:\ 加载 file:\,因为那将是一个巨大的安全漏洞。一个解决方案是 运行 一个基本的 HTTP 服务器来为 Bokeh HTML 文件提供服务,例如 python -m http.server(或 python -m SimpleHTTPServer for legacy Python 2)并让你的IFrame 从简单服务器加载 Bokeh 页面。