Knowledge Drop

How do I render a local image in Looker?

  • 5 April 2021
  • 5 replies
  • 568 views

Userlevel 5
Badge
  • Looker Staff
  • 171 replies

Last tested: March 2021

 

Looker expects a public URL for your image. So make sure that wherever you store it is publicly accessible. Then, you can call it in LookML like so:

view: view_name { dimension: field_name { html: <img src=”http://www.acme.com/product_images/my_image.jpg” /> ;; }}

This help center article goes more in depth on the modeling.

It's not possible to use a local image on your computer, or on the Looker server. It is also not possible to use non-public URLs, as Looker will have no way to authenticate.

 

This content is subject to limited support.                


5 replies

Hi guys, i wanted to know if it was still impossible to use a local image ?

I’m currently using images host on my server, but whenever i try to export dashboard containing those images, it export with no images.
 

Userlevel 5
Badge

@Irvin That’s correct. It’s not possible to use a local image - either on your own server or on the Looker server.  You’ve gotta use a URL.

 

If you can access Looker’s product feedback system, then you can upvote this feature request and leave more details with your use case!

 

Userlevel 1

Hi @Irvin, @sam 

If you need to add an image that should not be hosted on a public domain you can insert it as a base64 encoded string. This works in LookML as well as Text tiles. Please be aware that for larger images this renders the Text tile popup unresponsive. So, please make sure you have the content ready to paste and avoid editing within the online interface.

First encode the image into a base64 string (e.g. using python):

python -mbase64 image.png | tr -d '\n' > b64encoded.txt

Then insert a tile with a content like the following:

<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Grid US" />

Hi, @nicohein 

this solution works as intended with Text Tiles, but not with LookML.



I tried with the img you provided (which works well in a text tiles as i said), and this renders nothing but a white screen.

 



Do you have any solution to put base64 img in a dimensions in lookML ?

and thanks for the later response !

 

Userlevel 1

Hi @Irvin,

unfortunately I can be of very little help for this one. I just had a quick look and it seems like Looker has some validations for the source values.

While the following renders as it should:

<img src="dataimage" alt="Test" />;

Adding either a colon or a semi-colon makes src parameter disappears:

<img src=";" alt="Test" />; <!-- renders as --> <img alt="Test" />;
<img src=":" alt="Test" />; <!-- renders as --> <img alt="Test" />;

If I add a space the output indicates that Looker also applies url encoding which is not useful in your case:

<img src="data image" alt="Test"> <!-- renders as --> <img src="data%20image" alt="Test">

I would hope your images are not secret and you can do something like using GitHub e.g. 

dimension: logo {
label: "Logo"
type: string
sql: "" ;;
html: <img src="https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/svgs/solid/address-book.svg" alt="Test" />;;
}

or using a public bucket to host your static content.

Reply