简体   繁体   English

在iPython笔记本中显示带有JS的HTML文件

[英]Displaying an HTML file with a JS inside an iPython notebook

I have a piece of code in an iPython notebook that programmatically generates a folder named 'sound' containing the following files: index.html, canvas.js, graph.js and style.css. 我在iPython笔记本中有一段代码,它以编程方式生成一个名为'sound'的文件夹,其中包含以下文件:index.html,canvas.js,graph.js和style.css。

If I open index.html in my browser, I can see exactly the output I want: a graph with a nice JS animation representing vectors in and out of a process I am modeling. 如果我在浏览器中打开index.html,我可以看到我想要的输出:一个带有漂亮的JS动画的图形,表示我正在建模的过程进出的向量。

网络可视化

However, I would like to display the HTML file from inside the iPython notebook itself. 但是,我想从iPython笔记本本身内部显示HTML文件。

For that, I type the following code: 为此,我输入以下代码:

from IPython.display import IFrame
IFrame('/Users/useird/Desktop/sound/index.html', width=700, height=350)

Which returns the following: 返回以下内容: 404错误ipython笔记本

I am not an expert with css or js, but I think that iPython can display js inside an iframe, so what's wrong here? 我不是css或js的专家,但我认为iPython可以在iframe中显示js,所以这里有什么问题?

Thanks 谢谢

To explicitly answer this question, I post my comment here again. 要明确回答这个问题,我再次在此发表评论。

IPython uses the Tornado web server engine to serve the html pages. IPython使用Tornado Web服务器引擎来提供html页面。 Per default, the web server cannot access files above the start directory. 默认情况下,Web服务器无法访问启动目录上方的文件。 Otherwise, this would be a severe security exposure. 否则,这将是一个严重的安全风险。 Hence, to make your data available for the web server you have to place it in the notebook starting directory or in a subdirectory. 因此,要使您的数据可用于Web服务器,您必须将其放在笔记本起始目录或子目录中。

This applies not only to html pages, but also to images you want to display using tags. 这不仅适用于html页面,也适用于要使用标签显示的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM