Using a local Reveal.js library with your IPython slides

  |   Source   |   Minimap

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({
            'RevealHelpTransformer':{
                'enabled':True,
                'url_prefix':'reveal.js',
                },                
            })

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

open(outfile, 'w').write(body.encode('utf-8'))
  Click me to hide the output

Then, just serve the directory:

python -m SimpleHTTPServer 8000

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

xdg-open http://127.0.0.1:8000

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

NOTE: 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

Hope it helps.

Damián.

Don't forget this blog post is an ipynb file itself! So, you can download it from the "Source" link at the top of the post if you want to play with it ;-)

Comments powered by Disqus