r/IPython • • Oct 31 '15

How to share an interactive IPython notebook?

Hi,

I'm a university lecturer and I'd like to share an IPython notebook to students without forcing them to install Anaconda on their machine. I need it to be interactive, so that they can compute their own case studies for a homework (cloud.sagemath.com only allow to share html for now). Wakari could be used, but students would need to create an account, which is something I would avoid. Anyone knows a clever way to share an interactive IPython notebook?

Thanks!

8 Upvotes

7 comments sorted by

4

u/iodbh Oct 31 '15

Ipython notebook runs on a local webserver. You could run it a a public server.

I was (until yesterday) a university sysadmin and would have gladly helped a lecturer from my lab setting that up on our servers. Ask your sysadmin !

3

u/NomadNella Nov 01 '15 edited Nov 01 '15

I've read about using Docker (and here) to serve up an interactive IPython environment. Do you know anything about using that, or do you have an opinion?

(Also just found this docker image.)

4

u/Double-Down Nov 01 '15

In our experience that image doesn't work, while this image does. You need to run it with the appropriate tags and port forwards such that it can be accessed on the local network.

docker run -d -p 8888:8888 --name jupyterserver -e "PASSWORD=jupiter" -v ~/Student:/notebooks/Student:ro ipython/scipyserver

Functionality: -d causes the program to be run in the background, rather than hogging your terminal. --name set the server name. -e P "PASSWORD=XXX" sets the password for the server. -v mounts the directory inside the docker container to an external volume, specifically it mounts the folder /Notebooks/Student, which is visible to iPython within the container, to the folder /Student on the home directory of the host, wherever that is. I've appended :ro to this so that the students can't just modify the notebooks, but maybe that isn't the best solution. -p maps the port inside the container (right) to one on the host (left), which then allows you to connect to the notebook on your browser by entering https://localhost:8888.

If this doesn't work directly, you may need to configure Putty on the local machine, specifying the server address and appropriate port, and then once that has been run you can then access the server through the browser again. If you need to add anything, run the command

docker exec -it bash jupyterserver

Which allows you to access the terminal inside the container. From here you can run pip install, sudo apt-get etc. You can also includes modules from inside the browser view of the server, by including "!pip install ... " in a cell.

We are currently using this to set up a common environment for scientific computing in our lab, so the use case is a little different, but I think the principles are much the same. The key difference is likely to be this read/write thing.

3

u/iodbh Nov 01 '15

/u/Double-Down's answer has a lot of specific details so I'll give you my opinion : in this cas, it is a very good idea to use a docker container for two reasons :

  • security: a docker is an isolated environment. A python notebook being an interactive python shell, there are risks involved in running it on a server. This is largely mitigated by using an isolated environment.

  • practicality: a scientific python environment can be a little complicated to set up. Once you have your container with everything you need, you can distribute a ready-to-use environment with no additional setup required.

So - I don't know how things are organized at your university, but if you provide an already configured container to be ran on a student-accessible server to your sysadmin, he'll be a lot happier than if you just ak him to set everything up.

The downside to that is that you would have to learn how to use Docker if you haven't yet. But it's pretty straightforward and very much worth it in a scientific context (another advantage of docker is that it helps insure that others will be able to run your research code).

4

u/NomadNella Nov 01 '15 edited Nov 01 '15

I'm glad you asked about that since I need to set something up for my students in the next week or two also. I've been talking with my department's IT support about using a Docker image server like was done for try.jupyter.org. I just did a little pre-emptive looking and found this image.

(Also see "How did we serve more than 20,000 IPython notebooks for Nature readers?".)

3

u/Zrk Nov 01 '15

Earlier today I installed a jupyter server from the scipy-notebook docker image (https://hub.docker.com/r/jupyter/scipy-notebook/). It comes with many useful scientific packages pre-installed, and both python 2 and 3 kernels.

I got it working very easily when I allow the exposed port to be reached (URL like https://example.org:8888

I'm still fighting with some problems when putting it behind a reverse proxy in Apache but it's apparently related to my restrictive iptables configuration and not to jupyter.

So if you're willing to go with your students accessing it with the port number in the URL then the docker one-liner will do the job.

0

u/[deleted] Nov 01 '15

[deleted]

1

u/[deleted] Nov 01 '15

For a moment, I thought I would have to learn Docker. But It's alive! What a fantastic service!