3

How do I add a local image to an IJulia notebook? The image is in the same local network folder as the IPYNB file. The folder is accessed via a symbolic link. I've tried both relative and absolute file names.

<img src="test.png" alt="Image Test" style="width:600px">

![Image Test](test.png)

Both show up the same, as a broken image link with "Image Test" next to the symbol.

Jupyter Info:

Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

notebook server is 4.2.3-da472a5

Julia Info:

Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (NO_LAPACKE DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: liblapack.so.3
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

IJulia                        1.3.2
Jeremy
  • 621
  • 6
  • 20
  • 3
    I'm using `display(FileIO.load("img.png"))` (I've already added `FileIO`) but this may not be what you're looking for... – daycaster Nov 10 '16 at 12:10
  • It does work but it feels like a hack. Any idea how to do it through markdown? – Jeremy Nov 10 '16 at 12:51
  • Both of your options should work. Have you tried closing and reopening the notebook (or possibly the whole notebook server)? – David P. Sanders Nov 10 '16 at 13:14
  • @DavidP.Sanders, many times. I've been looking at it on and off again for weeks. At some point in the past it worked. After a fresh computer install and updating everything I went back to some old notebooks to update them and it didn't work anymore. – Jeremy Nov 10 '16 at 13:21
  • 1
    You _are_ changing the cell type to Markdown? (Silly question, but i can't think of anything else.) – daycaster Nov 10 '16 at 15:54
  • A silly question indeed but it's a very good silly question. Yes, after trying it 20+ times before realizing I wasn't on markdown I did switch it but to no avail. Neither of the methods in my original post worked in markdown. – Jeremy Nov 10 '16 at 16:07
  • Does it work in a new notebook document? – David P. Sanders Nov 10 '16 at 17:43
  • Great idea @DavidP.Sanders but that didn't work either. I tried both markdown methods with relative and absolute directories. – Jeremy Nov 11 '16 at 09:16

3 Answers3

5

![Image Test](test.png) works fine for me; maybe it has to be in the same directory as the one where jupyter is running, i.e. the directory shown in the top-level Jupyter dashboard?

(Without using FileIO, you can also do display("image/png", read("file.png")).)

The ability to directly drag-and-drop or copy-paste images into notebook cells was recently added to Jupyter, so hopefully it will be in the next major release (Jupyter 4.3 or 5?).

SGJ
  • 990
  • 6
  • 7
  • The relative URL should look in the same directory that the current notebook is in. – Thomas K Nov 10 '16 at 22:27
  • The display method does work but is only slightly better than the one @daycaster suggested above. I really want to figure out why markdown isn't working though. A notebook shouldn't need to be filled with hacks. – Jeremy Nov 11 '16 at 09:14
2

The answer was to move all the files to my hard drive. The folder I was using was on a local network. Even then only relative directories worked with both markdown methods.

Despite knowing what to do I don't yet know why. If somebody could suggest why this might be I would appreciate it.

Jeremy
  • 621
  • 6
  • 20
0

"(/notebooks/images/your_image.png)", this should work."notebooks" is just right after "localhost:xxxx/" in the search bar of your browser. Before this, I've tried both relative and absolute file names too, but failed. It seems Jupyter Notebook(in my case, ipython 6.3.1) does not support loading local images from any other place but the same one as the ipynb. Hope this would help.

GG.Fan
  • 151
  • 2
  • 5