IPython:向IPython笔记本添加Javascript脚本 [英] IPython: Adding Javascript scripts to IPython notebook
问题描述
作为项目的一部分,我需要在IPython模块中嵌入一些javascript。
这就是我想要做的:
来自IPython.display import display,Javascript
Javascript( 'echo(sdfds);',lib ='/ home / student / Gl.js')
My Gl.js看起来像这样
function echo(a){
alert(a);
}
是否有某种方式可以嵌入Gl.js和其他这样的笔记本内部的外部脚本,这样我就不必在每次尝试执行一些需要该库的Javascript代码时都将它们作为'lib'参数包含在内。
解决方案作为一个非常短期的解决方案,您可以使用IPython display()
和 HTML() 函数可以在页面中注入一些JavaScript。 $ b js =< script> alert('Hello World!');< / script>
display(HTML(js))
虽然我不推荐通过官方的 custom.js
方法,我确实有时会发现快速测试某些内容或动态生成一个小的JavaScript片段是有用的。
As a part of a project, I need to embedd some javascripts inside an IPython module. This is what I want to do:
from IPython.display import display,Javascript
Javascript('echo("sdfds");',lib='/home/student/Gl.js')
My Gl.js looks like this
function echo(a){
alert(a);
}
Is there some way so that I can embed "Gl.js" and other such external scripts inside the notebook, such that I dont have to include them as 'lib' argument everytime I try to execute some Javascript code which requires to that library.
As a very short-term solution, you can make use of the IPython display()
and HTML()
functions to inject some JavaScript into the page.
from IPython.display import display, HTML
js = "<script>alert('Hello World!');</script>"
display(HTML(js))
Although I do not recommend this over the official custom.js
method, I do sometimes find it useful to quickly test something or to dynamically generate a small JavaScript snippet.
这篇关于IPython:向IPython笔记本添加Javascript脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!