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?
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,
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
You can actually do it using only Google Colab.
Click on the
Files icon on the far left:
Upload to session storage:
Select & upload your
.ipynb file you just downloaded.
then obtain its path (you might need to hit the
Refresh button before your file shows up):
%%shell jupyter nbconvert --to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb
%%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
Might need to click
Refresh again, but your
notebook.html will appear in the files, so you can download it:
I tried the approach above but couldn’t get it to work – for small jobs I log onto https://jupyter.org/try , upload the downloaded ipynb file from Google Colab and then I opened the file, from here you will have the functionality in jupyter.org to download as html or whatever other format you require. It took the pain out of trying to get it to work.
to continue with "Method using only Google Colab"
" %%shell jupyter nbconvert –to html /PATH/TO/YOUR/NOTEBOOKFILE.ipynb" – as given
the following worked for me – type the following in Google Colab
!pip install nbconvert
%shell jupyter nbconvert –to html /content/testfile.ipynb
(instead of using %%shell in Google Colab, use %shell – this way, it worked for me)
PATH_TO_THE_NOTEBOOK_IN_COLABin the below command to the location of the reuploaded notebook.
!jupyter nbconvert --to html PATH_TO_THE_NOTEBOOK_IN_COLAB.ipynb.