Using a local Reveal.js library with your IPython slides

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

稿源:Damian's blog (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 手机数码 » Using a local Reveal.js library with your IPython slides

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录