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?
6 Answers
Method using Google Colab only
- Download your .ipynb file
You can actually do it using only Google Colab. File
-> Download .ipynb
- Reupload it so Colab can see it
Click on the Files
icon on the far left:
Then Upload to session storage
:
Select & upload your .ipynb
file you just downloaded.
- Get your file's path
then obtain its path (you might need to hit the Refresh
button before your file shows up):
- 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
.
- Your file is ready
Might need to click Refresh
again, but your notebook.html
will appear in the files, so you can download it:
The great thing about this is that nothing python-related has to be installed on your computer, not conda, not pip, only a browser.
-
1Unfortunately, this solution is only available with an upgraded account with costs. Mar 24, 2021 at 21:47
-
1No, none of the steps above require upgrading. Which step is causing you trouble?– zabopMar 24, 2021 at 21:56
-
I use similar methods in EU, UK, Norway, they work in all three of these places.– zabopMar 24, 2021 at 21:57
-
1This method works fine and I feel like should be the accepted answer as well! Thanks @zabop Mar 31, 2021 at 3:50
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
-
1Welcome to Stack Overflow! Great first answer. Minor nitpick: Conda is not a distribution of Python, Anaconda is. Conda is the package/dependency/environment manager.– alkasmMar 24, 2019 at 19:08
-
Thank you Alexander! You're right, Conda is only a package/env manager, a CLI for that matter. I've accordingly edited my answer. Mar 24, 2019 at 20:24
-
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)
-
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.– Community BotFeb 2, 2022 at 6:44
-
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Feb 6, 2022 at 21:32
- Download your notebook and upload it back to the colab
- Replace
PATH_TO_THE_NOTEBOOK_IN_COLAB
in the below command to the location of the reuploaded notebook. - Use this command to download the notebook as html =>
!jupyter nbconvert --to html PATH_TO_THE_NOTEBOOK_IN_COLAB.ipynb
.
I did all the steps mentioned above to get the file path but then ran this code (each line in it's own cell).
!pip install nbconvert
!jupyter nbconvert -- to html /ADD YOUR FILE PATH HERE.ipynb
from google.colab import files files.download('ADD YOUR FILE PATH HERE.html')
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.