11-28-2019 11:13 AM
Hi everyone,
I just learning how to personalize the databricks notebooks and would like to show a logo in a cell.
I installed the databricks cli and was able to upload the image file to the dbfs:
I try to display it like this:
displayHTML("<img src ='files/Omnetric_logo.jpg'>")
Is not working:
If I used the full URI of the image, same result:
displayHTML("<img src ='dbfs:/FileStore/files/Omnetric_logo.jpg'>")
I also tried with a "images" folder instead of "files", again, same result.
Could you please help me with that. Any comment will be appreciated.
Best,
Paul
12-02-2019 08:45 AM
Hi @Paul Hernandez, please try adding a preceding slash before the
files
path:
displayHTML("<img src ='/files/Omnetric_logo.jpg'>")
Just to add as a design pattern - I like to have any static content contained in a markdown block. Most notebooks/workshops I've seen produced by Databricks also do this. That is, you would use the
%md
magic command at the top of your block and allow markdown to render the html, along with any other markdown you like:
%md
<img src ='/files/Omnetric_logo.jpg'>
# Hello Omnetric
## Overview
Blah Blah Blah
- list item 1
- list item 2
## Details
Blah blah
12-01-2019 10:49 PM
Hi @Paul Hernandez,
Please use IPython library as in below,
from IPython.display import Image
from IPython.core.display import HTML
Image(url= "https://docs.databricks.com/_images/landing-aws.png")
12-02-2019 02:22 AM
Hi @Shyamprasad Miryala , thanks for your input!
I gave you a point because your code is working and helped me workaround the issue.
However, I still would like to know why the approach using html and images stored in dbfs is not working, therefore I could not mark your solution as the answer.
Best, Paul
12-02-2019 08:45 AM
Hi @Paul Hernandez, please try adding a preceding slash before the
files
path:
displayHTML("<img src ='/files/Omnetric_logo.jpg'>")
Just to add as a design pattern - I like to have any static content contained in a markdown block. Most notebooks/workshops I've seen produced by Databricks also do this. That is, you would use the
%md
magic command at the top of your block and allow markdown to render the html, along with any other markdown you like:
%md
<img src ='/files/Omnetric_logo.jpg'>
# Hello Omnetric
## Overview
Blah Blah Blah
- list item 1
- list item 2
## Details
Blah blah
12-03-2019 04:34 AM
Hi @leedabee,
thanks! I used your snippet for my notebook and it works.
I also had to correct the url of the image. Since I uploaded the file in dbfs:/FileStore and then in a subfolder called images, the right url is:
/files/files/Omnetric_logo.jpg
Reviewing the documentation I noticed that dbfs:/FileStore is mapped to files
Best, Paul
05-13-2020 01:12 AM
Hi @Paul Hernandez , Did you find a resolution to displaying the images? Image('xyz.png') results with <IPython.core.display.Image object> and no image.
09-15-2021 04:58 PM
For small images, another cheeky alternative is to base64-encode the image bytes and construct a data:/ URI out of it, and make a hyperlink to that. It is 'inline' in the notebook then, but, wouldn't be a good idea for big images.
10-12-2021 09:39 AM
@Paul Hernandez @Sean Owen @Navneet Tuteja I solved this after I also ran into the same issue where my notebook suddenly wouldn't show an image sitting on the driver in an accessible folder - no matter what I was trying in the notebook the display function only returned <IPython.core.display.Image object> as output.
After investigating, I found the file was returning as raw bytes instead of the formatted image (even though it was saved as a png it was raw bytes). Even after encoding for mimetypes manually as well as a few other format conversion attempts it still only rendered <IPython.core.display.Image object> and no image. Like huh?
My Solution (Verified using Community Edition):
Reviewing Ipython.display driver dependencies to see if the runtime itself was having issues was successful, as simply updating the cluster's runtime from [Databricks 8.3 (includes Apache Spark 3.1.2, Scala 2.12)] to [8.4 (includes Apache Spark 3.1.2, Scala 2.12)] which gave me a fresh install of Ipython.display in the notebook, the png/images referenced in the notebook started rendering as normal again. Go down to 8.2 did not fix the display render. The likely root cause appeared to be mimetype conversion, usually handled by Ipython.display in the call, so if you take a look at your file you may see raw bytes even though the file type is assigned (png in my case), which means the file's raw data isn't being formatted/converted properly and the notebook returns an object to render instead of a supported file format.
Summary: Refresh Ipython to a newer version by updating to a newer runtime may solve the problem, assuming everything in notebook is correct.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group