Data Science

F# Notebooks for the Barely Connected

Published on

F# Notebooks for the Barely Connected

While Azure Notebooks might be the fastest and easiest way to do F# data science experiments on Jupyter notebooks, but that only works if you’re always online. What if you’re in a third world country (like me) and only have intermittent internet connectivity? How would you work with F# on Jupyter notebooks?

We have a solution for that. But of course, you need to go online first. After that, you can be offline all you want and still do work with the F# that you love in your favorite Jupyter notebook.

Docker to the rescue

The people behind F# already thought about that and built a Dockerfile for running an F# notebook in Docker

Asciicast of the process

So how do we do this?

  1. First, the IfSharp repo is cloned.
  2. Then we go into the IfSharp directory.
  3. We then build the Docker image from the Dockerfile with docker build -t ifsharp:3.0.0-alpha .
  4. We then run the image using docker run -d -v your_local_notebooks_dir:/notebooks -p your_port:8888 ifsharp:3.0.0-alpha. Change the port and the notebook location.
  5. After that, we use docker ps to see the running container. We copy the id if the running container.
  6. We open a bash shell inside the running container with docker exec -it the-container-id /bin/bash. Replace `the-container-id` with the container ID we copied.
  7. Run jupyter notebook list to see the running notebook. Copy the token after the ?token= part of the URL.
  8. Open the notebook in localhost and paste the token to get access to the notebook.

After opening the notebook, we are met with this:

That is where we paste the token that we copied earlier. Paste it there on top and press Log in.

Congratulations! You can now create F# notebooks like this:

Now you can do your F# experiments on a Jupyter Notebook even when offline! Yey!

If you liked this post please Buy Me a Coffee at ko-fi.com