Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blank page when using --to slides offline #296

Open
Daniel-at-github opened this issue Apr 20, 2016 · 7 comments
Open

blank page when using --to slides offline #296

Daniel-at-github opened this issue Apr 20, 2016 · 7 comments
Assignees
Labels
format:Slides pertains to exporting to the Slides format

Comments

@Daniel-at-github
Copy link

(Not a duplicate of #91)

Online this steps works flawlessly for me:

git clone https://github.com/hakimel/reveal.js.git
jupyter nbconvert Untitled.ipynb --to slides
xdg-open Untitled.slides.html

But when I pull the network cord, clear all browser history (cache, ...) open same html... then blank page.
Attach network cord, refresh browser. All good again.

I need to show the slides in a offline location. I Keep trying (with the same result):

jupyter nbconvert Untitled.ipynb --to slides --post serve
jupyter nbconvert Untitled.ipynb --to slides --post serve --reveal-prefix=./reveal.js

Looking what the slides get from the net. I get:

No mention of this in the docs http://nbconvert.readthedocs.org/en/latest/usage.html#convert-revealjs.

If any of this (require.js, jquery, MathJax, fonts) could be added manually. Please document how.

My environment for this issue:
Ipython

python -c "import IPython; print(IPython.sys_info())"
{'commit_hash': 'b573435',
 'commit_source': 'installation',
 'default_encoding': 'UTF-8',
 'ipython_path': '/home/user/.virtualenvs/nbconvert3/lib/python3.4/site-packages/IPython',
 'ipython_version': '4.1.2',
 'os_name': 'posix',
 'platform': 'Linux-3.13.0-85-generic-x86_64-with-Ubuntu-14.04-trusty',
 'sys_executable': '/home/user/.virtualenvs/nbconvert3/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.4.3 (default, Oct 14 2015, 20:28:29) \n[GCC 4.8.4]'}

Virtualenv

pip freeze
backports-abc==0.4
decorator==4.0.9
entrypoints==0.2
ipykernel==4.3.1
ipython==4.1.2
ipython-genutils==0.1.0
ipywidgets==4.1.1
Jinja2==2.8
jsonschema==2.5.1
jupyter-client==4.2.2
jupyter-core==4.1.0
MarkupSafe==0.23
mistune==0.7.2
nbconvert==4.2.0
nbformat==4.0.1
notebook==4.1.0
pexpect==4.0.1
pickleshare==0.7.2
ptyprocess==0.5.1
Pygments==2.1.3
pyzmq==15.2.0
simplegeneric==0.8.1
terminado==0.6
tornado==4.3
traitlets==4.2.1

Browser

firefox --version
Mozilla Firefox 45.0.2
@takluyver
Copy link
Member

Ping @damianavila - I'm sure we originally intended exported slides to work offline, and there's a config setting to point it to a different revealjs location. But it looks like several hardcoded CDN URLs have crept in.

@takluyver takluyver added the format:Slides pertains to exporting to the Slides format label Apr 21, 2016
@fisadev
Copy link

fisadev commented Sep 24, 2016

Today I was hit by this issue too. In a few hours I have to give two talks (with slides created using ipython) in a place where won't be a stable internet connection, so I had to find an older version of ipython in which this bug doesn't happen. And to make things more complicated, that older version isn't able to open notebooks from more modern versions. In case anyone needs a temporary quick fix as me, this is what you should do (assuming you have a notebook done with recent versions of ipython):

  1. Install ipython[notebook]==2.4
  2. Open the notebook and save it
  3. Install ipython[notebook]==2.0
  4. Open the notebook and save it

The 2.4 step is needed because 2.0 can't open notebooks from recent versions, while 2.4 can. And then you still need to go back to 2.0, because 2.4 has the offline issues, while 2.0 doesn't.

@damianavila
Copy link
Member

Thanks for the detail report @fisadev, I will look into this soon.

@deroulers
Copy link

deroulers commented Jan 23, 2017

A relatively clean workaround (tested with jupyter-nbconvert 4.2.0), I think:

  1. Make a copy of nbconvert's files site-packages/nbconvert/templates/html/slides_reveal.tpl and site-packages/nbconvert/templates/html/mathjax.tpl into the slides' directory. To avoid confusion and reusing by mistake the standard templates, let us name these copies slides_reveal_local.tpl and mathjax_local.tpl respectively.

  2. Edit the copies to replace references to files retrieved from the net to references to your local mirror of Ajax, MathJax and so on.

  3. Modify your local copy slides_reveal_local.tpl to refer to the new name mathjax_local.tpl instead of mathjax.tpl.

  4. When generating the slides, add option --SlidesExporter.template_file="slides_reveal_local" to the command line of jupyter-nbconvert so that your template is used.

FWIW, here are Makefile rules I use to automatically generate the templates (my local CDN lies in the CDN subdir; my installation of jupyter-nbconvert was done through MacPorts, hence the commands $(shell port...) to find the path to the template files):

all: slides_reveal_local.tpl mathjax_local.tpl
        jupyter-nbconvert-3.4 --to slides --post serve \
          --SlidesExporter.template_file="slides_reveal_local" file.ipynb

slides_reveal_local.tpl: $(shell port contents py34-nbconvert|grep slides_reveal)
        @echo "Remaking "$@" from "$<
        sed -e 's/https:\/\/cdnjs\.cloudflare\.com\/ajax\/libs/CDN/' \
          -e 's/\/\/netdna\.bootstrapcdn\.com/CDN/' \
          -e 's/mathjax\.tpl/mathjax_local.tpl/' $< > $@

mathjax_local.tpl: $(shell port contents py34-nbconvert|grep mathjax)
        @echo "Remaking "$@" from "$<
        sed -e 's/https:\/\/cdn\.mathjax\.org\/mathjax\/latest/CDN\/MathJax/' \
          $< > $@

This does not (yet) handle the problem of Google's fonts.

@damianavila
Copy link
Member

Currently, in the last released version of nbconvert you can pass custom stuff for jquery, font-awesome and require: https://github.com/jupyter/nbconvert/blob/master/nbconvert/exporters/slides.py#L106-L131.

Still we need to figure out the fonts and mathjax cases and test all locally.

@ashwinvis
Copy link

ashwinvis commented Dec 9, 2017

@damianavila Shouldn't the MathJax case be straightforward like adding an option as follows?

c = get_config()
c.SlidesExporter.mathjax_url = './CDN/MathJax-2.7.1/MathJax.js'

Since this not solved yet, let me extend @deroulers 's workaround to a more generic Makefile for nearly all POSIX platforms. I have assumed the same local directory CDN.

NBCONVERT_ROOT := $(shell pip show nbconvert | awk '/Location/{printf("%s/%s", $$2, "nbconvert")}')

CDN/%.tpl: $(NBCONVERT_ROOT)/templates/html/%.tpl
	cp -f $< $@
	sed -i -e 's/https:\/\/cdnjs\.cloudflare\.com\/ajax\/libs/CDN/' $@

cleantpl:
        rm -f CDN/*.tpl 

localize: cleantpl CDN/mathjax.tpl CDN/slides_reveal.tpl
	sed -i -e 's/mathjax\/2\.7\.1/MathJax-2\.7\.1/' CDN/mathjax.tpl

Note that the above rules expects a MathJax-2.7.1 directory extracted from the release. Get it as follows:

wget https://github.com/mathjax/MathJax/archive/2.7.1.tar.gz -o CDN/MathJax-2.7.1.tar.gz
tar -xf CDN/MathJax-2.7.1.tar.gz -C CDN

Also add this to the configuration file: c.SlidesExporter.template_file = './CDN/slides_reveal.tpl' or alternatively like a console option --SlidesExporter.template_file='./CDN/slides_reveal.tpl'.

@alexisfcote
Copy link

I have made a hacky solution to convert notebook to offline slides.
See here https://github.com/alexisfcote/offline_slides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format:Slides pertains to exporting to the Slides format
Projects
None yet
Development

No branches or pull requests

7 participants