How to Add Images to Visualizations

Looker will not be updating this content, nor guarantees that everything is up-to-date. 

The Problem


I have pictures that I want to show in my Looker visualization. In a dataset of companies, I could use this to replace a company name with an image in a visualization:
 

29cfb4ca-4e0e-4c03-8e2f-b6008b9150a5.png

The Solution


We can use the html LookML parameter to have Looker render HTML instead of just showing a text value. In this case, we can use HTML's img tag to have a field just render a picture:

dimension: looker_image {
type: string
sql: ${TABLE}.homepage_url;;
html: <img src="https://logo-core.clearbit.com/looker.com" /> ;;
}
e29108dc-bc4c-439c-9300-0b5a45eb74e8.png

The text for each of the rows has now been replaced by the image defined in the img tag of the HTML.
 

Dynamic Images


The next step is to make my images change based on the value of the row. We can input the value of the row into the html parameter using the Liquid variable {{value}}. We can add this to the image URL in a slightly modified version of the dimension above:

dimension: brand_images {

  type: string

  sql: ${TABLE}.homepage_url;;

  html: <img src=”https://logo-core.clearbit.com/{{value}}” />;;



Now, the URL will change for each row. In this example, we append company URLs to the end of https://logo-core.clearbit.com/, which is a website that provides many company logo images based on the URLs. Other examples might include using a numeric {{value}} to denote which image to use.

Comments
nathan-michel
Observer

Thanks for this article which is exactly what I was looking for ! I just don’t understand what is “homepage_url” ?

thomasrose
Participant I

Thanks for this article which is exactly what I was looking for ! I just don’t understand what is “homepage_url” ?

homepage_url is in this case just a database field in a table which contains informations about i.e. companies. Expect something like

company_name | adress        | homepage_url            

ACME Corp    | Acme Lane 42  | acme.com        


The html of the brand_image dimension would now point to img src=”https://logo-core.clearbit.com/acme.com” as “value” would be substituted from the sql-attribute data

nathan-michel
Observer

Thanks for this article which is exactly what I was looking for ! I just don’t understand what is “homepage_url” ?

homepage_url is in this case just a database field in a table which contains informations about i.e. companies. Expect something like

company_name | adress        | homepage_url             ACME Corp    | Acme Lane 42  | acme.com        

The html of the brand_image dimension would now point to img src=”https://logo-core.clearbit.com/acme.com” as “value” would be substituted from the sql-attribute data

Thanks Thomas, it’s really clear ! 😄

Version history
Last update:
‎06-22-2022 02:24 PM
Updated by: