How to Share your Jupyter Notebook in 3 Lines of Code with Ngrok | by Khuyen Tran | Towards Data Science

Have you ever wanted to share your Jupyter Notebook with your friend to collaborate on a project but found no collaboration button? You cannot just copy and paste the link of your Jupyter Notebook because it runs on the local machine. You wish there could be a way that you could just send your friend a link and both of you can work on the same notebook. If one person makes a change in the notebook, another person will see the change as well.
Google Colab allows you to share your notebook. Where is the share button in Jupyter Notebook? Before switching from Jupyter Notebook to Google Colab for collaboration, you could consider the alternative: creating the public server for your Jupyter Notebook with ngrok.
What is ngrok? Ngrok exposes your local servers behind NATs and firewalls to the public internet over secure tunnels. This means that you can provide your local server to the port of a web server. As you access to that web server, you should be able to get to the local address you specified. With 3 lines of codes on your terminal, you will obtain a public URL of your Jupyter Notebook that is ready to share!
Start with install the ngrok here. Then sign up for ngrok account. After signing up, you should be able to obtain your tunnel authtoken here.
Copy and paste the code for authtoken to the terminal. Once you have linked your machine with authtoken to this account, you don’t need to redo this in the future.
Next, allow the Jupyter Notebook to be accessed remotely by changing the configuration of your Jupyter Notebook
jupyter notebook --generate-config
You will see the link address to the configuration file of your Jupyter Notebook. In my machine, that link is /Users/khuyentran/.jupyter/jupyter_notebook_config.py. Copy that address. Then run the code below
echo "c.NotebookApp.allow_remote_access = True" >> ~/.jupyter/jupyter_notebook_config.py
For extra security, set the password for your Jupyter Notebook
jupyter notebook password
Then tell ngrok what port your jupyter notebook is running on. If your port is 8888. Type:
./ngrok http 8888
You should see the result below
Click on the link http://b32b5f59.ngrok.io to access to the public URL of your tunnel.
That’s it! Now you should be able to copy and paste the link you generated and share it with your friends and colleagues! Make sure to tell them your password to access the notebook.
Congratulations! You have learned how to share your Jupyter Notebook and work with it on a different machine. One thing to notice is that since this public webserver connects to your local machine if you terminate the server in your local machine, the public URL of your tunnel will be terminated as well. So make sure your server is running when if you want the Jupyter Notebook to run in a different machine.
Last but not least. Run this command line on your terminal:
say "Thank you for reading this article"
I like to write about basic data science concepts and play with different algorithms and data science tools. You could connect with me on LinkedIn and Twitter.
Star this repo if you want to check out the codes for all of the articles I have written. Follow me on Medium to stay informed with my latest data science articles like these: