19

Export Google Colab Notebook as HTML Webpage

 2 years ago
source link: https://joets.medium.com/export-google-colab-notebook-as-html-webpage-39734a3d195e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Export Google Colab Notebook as HTML Webpage

Export HTML from Colab without additional tools.

1*Z8q8UIiJvDP8BjMvIdyTHQ.png
images by Author

Google Colab (Collaboratory)[1] is a (Swiss Army Knife) Jupyter Notebook IDE that most data scientists or Python users know of. It comes with free access to GPU and TPU. All you need is a Google Account to get started with. I usually recommend people to get started and learn Python by using the Jupyter Notebook with Colab. After you are done with the Colab project, it is nice to share your awesome work and your research finding with people. In this article, I would like to recommend one way to share Colab's work on your own web page as an HTML file. This method also works with any IPYNB file even if you did not use the Colab to write the script.

Step 1: Locate the IPYNB file and Copy Path

In the Colab, just browse the file panel. If you already sync the G-Drive to your Colab, usually the IPYNB directory is located in content/drive/MyDrive/Colab Nodebooks/... After finding the IPYNB file, right-click on it, and click “Copy path” as shown in fig 1.

1*ee15-jE0OCNq1ot5HtBf1A.png
fig 1: Locate the IPYNB file and Copy Path. (by Author)

If you have the IPYNB file from other sources, just upload the file to Colab using the “Upload to session storage” on the topper left of the file manager tab (fig 2). Then, you can copy its path the same way as in fig 1.

1*L9XVNT7LpANBwPUSIkMvIQ.png
fig 2: Upload IPYNB file generated outside of Colab. (by Author)

Step 2: Conversion [IPYNB to HTML]

You may add the following line to the code block at the end of your script to export IPYNB to HTML.

%%shell
jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb

As the command will be run as a shell, use a distinct cell for it. Do not add it to other Python cells. Then, after you run your notebook again, the HTML file will be created at the same directory as shown in fig 3.

1*MmJ1PZs8el6ILF1dXIz86w.png
fig 3: Conversion from IPYNB to HTML using Shell command inside COLAB. (by Author)

Last Step: Share your work.

You can see the HTML result in the COLAB file manager pane after refreshing it by right-click and clicking “refresh”. Then, you can download it to your PC. After you get the HTML output, you can share it on any simple web server.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK