Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

embedding image into jupyter notebook and exporting to HTML

I am running Python 3.7 on Windows using pycharm. I have a jupyter notebook and I would like to embed an image into the notebook. I know all the ways of doing standard embedding with markdown language, BUT ideally what I want is:

a. Embed the image via markdown language, i.e. the notebook cell is in 'markdown' state, not 'Code' state, AND ALSO

b. Have it able to export to HTML and retain that image in the HTML file. i.e. on the notebook. I want to click File -> Download as -> HTML (.html), save the notebook file in .html format, and then when I send it to my buddy, the image that I attached is in the notebook, and he sees it.

I know i could do this in a cell ('code'):

from IPython.display import Image
Image(filename="myfile.jpg")

but I do not want to use 'Code', since when I send to my buddy, he will see the In [] code statement and the Out [] of the image in the notebook html file.

Note: This would be an image that was on my laptop that I would want in the html formatted exported notebook. It is NOT on the web where he could refer to it with a www type statement. Unless I'm crazy, there is no way to do this with markdown command in a cell, the only way to do it (with the image embedded 'permanently' into the .html format of the notebook), would be via a cell that was in 'Code' celltype.

like image 921
TexasTom Avatar asked Aug 22 '18 21:08

TexasTom


People also ask

How do I export a Jupyter Notebook output to HTML?

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. Screenshot of export by author.

Can you embed images in a Jupyter Notebook?

Method 1: Direct insertion using the edit menu first, change the type of the cell to -> markdown. Step 2: After that click edit in the jupyter notebook menu. after that click 'insert image'. Edit -> insert image.

How do I export an image from a Jupyter Notebook?

However, there's an easy workaround: You can just Shift+Right click to see the normal right-click menu and then save the image to a file.

Can we use Jupyter Notebook for HTML?

Notebooks may be exported to a range of static formats, including HTML (for example, for blog posts), reStructuredText, LaTeX, PDF, and slide shows, via the nbconvert command. Furthermore, any . ipynb notebook document available from a public URL can be shared via the Jupyter Notebook Viewer <nbviewer>.


1 Answers

You can install the Unofficial Jupyter Notebook Extensions.

It has some interesting extensions (e.g. spell checker, collapsible headings, ...). One of the extensions is Export HTML With Embedded Images which exactly does what you want.

To install Nbextensions using pip do the following:

$ pip install jupyter_contrib_nbextensions
$ pip install jupyter_nbextensions_configurator
$ jupyter contrib nbextension install --user 
$ jupyter nbextensions_configurator enable --user

Then you will see in your Jupyter homepage a new tab (Nbextensions), where you can enable and configure different extension.

After enabling the "Export HTML With Embedded Images", you will see the corresponding option in the "File-Download as" menu.

like image 145
zardosht Avatar answered Oct 27 '22 01:10

zardosht