Using a local Reveal.js library with your IPython slides

手机数码 2013-09-14

IPython slides are powered by Reveal.js
library, you probably already know that.

But... you probably don't know that we use jsdelivr
CDN to load all the necessary js and css files. As a consequence, you don't need to download Reveal.js, but also, the speaker notes are not working by default.

But... what happens, if you have low connectivity in the place where you will be presenting your talk (or if you want to use the speaker notes feature)?

In this case, it would be better to use a local copy of the Reveal.js library. And you can easily configure this behavior using a config object from the IPython machinery.

Below, you have one way to do it:

In [1]:

from IPython.nbconvert.exporters import SlidesExporter
from IPython.config import Config

from IPython.nbformat import current as nbformat

infile = "talk.ipynb" # load the name of your slideshow
outfile = "talk.slides.html"

notebook = open(infile).read()
notebook_json = nbformat.reads_json(notebook)

# This is the config object I talked before: 
# After the 'url_prefix', you can set the location of your 
# local reveal.js library, i.e. if the reveal.js is located 
# in the same directory as your talk.slides.html, then 
# set 'url_prefix':'reveal.js'.

c = Config({

exportHtml = SlidesExporter(config=c)
(body,resources) = exportHtml.from_notebook_node(notebook_json)

open(outfile, 'w').write(body.encode('utf-8'))

Click me!

Then, just serve the directory:

python -m SimpleHTTPServer 8000

open the browser and point it to http://localhost:port
, ie:


OK, that's all... you don't need connectivity anymore 😉 OK, just kidding... he he!

: If you are using master, it is even simpler... because now --post serve
post-processor uses tornado to forward requests to the CDN if and only if local Reveal.js is unavailable (PR merged here
, thanks MinRK
). So, just locate the reveal.js
in the same directory as your talk.slides.html lives and run (as usually):

ipython nbconvert talk.ipynb --to slides --post serve

You can also point to another directory using the --reveal-prefix
alias, ie:

ipython nbconvert talk.ipynb --to slides --post serve --reveal-prefix foo/reveal.js

责编内容by:Damian's blog (源链)。感谢您的支持!


利用 Python 进行数据分析 中文第二版 第2章 Python语法基础,IPython和Jupy... 当我在2011年和2012年写作本书的第一版时,可用的学习Python数据分析的资源很少。这部分上是一个鸡和蛋的问题:我们现在使用的库,比如pandas、scikit-learn和statsmodels,那时相对来说并不成熟。2017年,数据科学、数据分析和机器学习的资源已经很多,原来通用的科学计算...
Jupyter receives the ACM Software System Award It is our pleasure to announce that Project Jupyter has been awarded the 2017 ACM Software System Award , a significant honor for the project. We ...
IPython 5.5.0 和 6.2.0 发布,Python 命令行交互... IPython 5.5.0 和 6.2.0 已发布,IPython 6.2 包含 IPython 5.5 中所有可用的功能和修复,并额外包含一些新特性,建议直接安装 6.2.0 。 相关文档: 6.x 系列 5.x 系列 IPython 是 Pytho...
A ‘poor man’ spell checker for the IPy... OK, today I will release another IPython js extension: Spellchecker , which obviously do what you are thinking... s...
python学习记录_IPython基础,Tab自动完成,内省,%run命令_... 这是我第一次写博客,之前也有很多想法,想把自己所接触的,以文本的形式储存,总是没有及时行动。此次下定决心,想把自己所学,所遇到的问题做个记录共享给诸位,与此同时自己作为备忘,感谢各位访问我的博客,欢迎指教。2018-03-27 12:34:31 学习书目《利用Python进行数据分析》 IP...