Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ipynb notebook to HTML in Google Colab

I have a Google Colaboratory Notebook for Data Analysis that I want to output as a HTML file as currently not everything loads within the Colab environment such as large Folium Heatmaps. Is it possible to export the notebook as a html file as opposed to the ipynb and py options?

like image 317
spaghetticode Avatar asked Nov 24 '18 16:11

spaghetticode


People also ask

How do I turn a Jupyter notebook into HTML?

Jupyter Notebook's Built-In Capability: If including code, this is the easiest way to create the JNaaP. This method is as simple as clicking File, Download as, HTML (. html). Jupyter will then download the notebook as an HTML file to wherever the browser defaults for downloaded files.

Is it possible to save a Google Colaboratory notebook to HTML?

Colab at the moment does not have an option to save your Colab notebook to HTML, Jupyter Notebook has an option to 'Download as' HTML (or other) format.


3 Answers

Method using only Google Colab

  1. Download your .ipynb file

You can actually do it using only Google Colab. File -> Download .ipynb


  1. Reupload it so Colab can see it

Click on the Files icon on the far left:

enter image description here

Then Upload to session storage:

enter image description here

Select & upload your .ipynb file you just downloaded.


  1. Get your file's path

then obtain its path (you might need to hit the Refresh button before your file shows up):

enter image description here


  1. Conversion using %%shell

Then, just as in Julio's answer, execute in a Colab cell:

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

The %%shell lets the interpreter know that the following script is interpreted as shell. Don't write anything before %%shell, use a distinct cell for this.

The form of /PATH/TO/YOUR/NOTEBOOKFILE.ipynb will be something like /content/lightaberration3.ipynb.


  1. Your file is ready

Might need to click Refresh again, but your notebook.html will appear in the files, so you can download it:

enter image description here


The great thing about this is that nothing python-related has to be installed on your computer, not conda, not pip, only a browser.

like image 58
zabop Avatar answered Sep 20 '22 15:09

zabop


Google Colab doesn't currently have such a feature as a built-in.

Your best route is to first download it through File > Download .ipynb and then use the standard tool for Jupyter Notebook conversion, nbconvert:

jupyter nbconvert --to html notebook.ipynb 

If you use an Anaconda Python distribution, nbconvert is most likely already installed. If not, refer to what is described in their install instructions to be able to convert:

pip install nbconvert # OR conda install nbconvert 
like image 24
Julio Cezar Silva Avatar answered Sep 20 '22 15:09

Julio Cezar Silva


  1. Download your notebook and upload it back to the colab
  2. Replace PATH_TO_THE_NOTEBOOK_IN_COLAB in the below command to the location of the reuploaded notebook.
  3. Use this command to download the notebook as html => !jupyter nbconvert --to html PATH_TO_THE_NOTEBOOK_IN_COLAB.ipynb.
like image 23
Sanjay S Avatar answered Sep 20 '22 15:09

Sanjay S