This article is written with help and examples from James Nestler - Customer Support Analyst, Looker Support (DCL).
The Problem
We can add images to Looker dashboards by hard-coding an image URL in a markdown text tile. However, images in text tiles are static and will not update based on results. What if we want a dashboard image to dynamically change based on a filter value?
This Help Center article demonstrates how to achieve a dynamic dashboard image using Liquid and the html
parameter.
The Solution
As a developer, I want to display a brand logo on a dashboard that will update based on the brand by which an end user chooses to filter.
The following solution is based on an e-commerce data set that includes a field called product.brand
, representing the brands in my data set:
dimension: brand { type: string sql: ${TABLE}.brand ;; }
Step 1: Creating a Logo Dimension in LookML
First, navigate to the project and view file containing the dimension to which you would like to add images. Then, create a new dimension based on that field, specifically for the use of displaying the images.
We will add an html
parameter for defining a Liquid {% if %}
conditional statement with the value
variable, for each value for which we want to display an image.
For example, the brand_logo
dimension below establishes a condition for displaying the specified images (with html <img>
tags) when the value of brand
is "O'Neill"
, "Calvin Klein"
, "Hanes"
, or "Tommy Hilfiger"
. For all other brands, we display a "no image available" icon:
dimension: brand_logo { type: string sql: ${brand} ;; html: {% if brand._value == "O'Neill" %} <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/1b/O%27Neill_%28brand%29_logo.svg/220px-O%27Neill_%28brand%29_logo.svg.png"> {% elsif brand._value == "Calvin Klein" %} <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Calvin_klein_logo.svg/220px-Calvin_klein_logo.svg.png"> {% elsif brand._value == "Hanes" %} <img src="https://upload.wikimedia.org/wikipedia/en/thumb/f/f0/Hanes-logo.svg/150px-Hanes-logo.svg.png"> {% elsif brand._value == "Tommy Hilfiger"%} <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Tommy_hilfig_vectorlogo.svg/250px-Tommy_hilfig_vectorlogo.svg.png"> {% else %} <img src="https://icon-library.net/images/no-image-available-icon/no-image-available-icon-6.jpg" height="250" width="300"> {% endif %} ;; }
You will need to hard-code a value condition for each value for which you would like to display an image.
Step 2: Creating the Dynamic Image Dashboard Tile
Now that the image dimension (brand_logo
) has been created, we can build an Explore that will become the dynamic image dashboard tile.
Build your Explore with the following criteria:
- Add a filter for the original dimension (in this case,
brand
). Set the filter for any value (the brand logo will display the "no image available" image in this case, as no specific filter value is selected). This filter value will update according to what the user selects for the dashboard filter. - Select the image dimension (in this case,
brand_logo
), and any other dimensions that may be necessary to the query that determines the image (for example, if you want to factor in a date, you can include date, etc.). - Change the row limit to one row.
- Change the visualization type to a single value visualization, and hide any other columns except the image dimension (
brand_logo
).
Your Explore should look something like this:
Save the Explore to a dashboard as a tile.
Step 3: Adding Dashboard Filters and Final Touches
Now, we will need to add dashboard filters to the dashboard. The filters on the dashboard will update the filter in the Explore to change the image displayed based on user input.
When creating the dashboard filter, make sure to include the following:
- The filter should be a
field type
filter on the original dimension. In the case of this example, the field for the filter will bebrand
. - Select the image tile in the Tiles to Update section. Select the original dimension (
brand
in this case) in the inline Choose Field drop-down menu. You can select other tiles to update as desired. - Optionally, customize the filter in the Customize Filter menu to require a filter value to run the dashboard, or switch off the Allow multiple filter values option to allow only one value input at a time.
Your filter will look like this:
Now, the image tile will update with the user filter selection:
Additional Resources
For more HTML and liquid formatting inspiration, check out the following Help Center articles: