How to Add Images to Visualizations

  • 22 June 2022
  • 3 replies
  • 2239 views

Userlevel 5
Badge
  • Looker Staff
  • 172 replies

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:
 

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" /> ;;
}

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.


This topic has been closed for comments

3 replies

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

Userlevel 1

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 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 ! :D