Okay, you can display images hosted at URLs within Looker, primarily in table visualizations, by using the html parameter in a LookML dimension.
Here's how you do it, along with explanations and examples:
Core Concept:
You'll define a LookML dimension that fetches the image URL (or constructs it). Then, you use the html parameter within that dimension definition to wrap the URL in an HTML <img> tag. Looker renders this HTML in the table cell.
Example 1: Simple Image Display
Let's assume you have a column in your database table called product_image_url that contains the full URL to an image.
lookml
view: products {
sql_table_name: public.products ;;
dimension: product_id {
primary_key: yes
type: number
sql: ${TABLE}.product_id ;;
}
dimension: product_name {
type: string
sql: ${TABLE}.name ;;
}
# (Hidden or visible) Dimension containing the raw image URL string
# You might hide this if you only want to show the image itself.
dimension: image_url_raw {
label: "Image URL (Raw)"
type: string
sql: ${TABLE}.product_image_url ;;
hidden: yes # Often hidden
}
# Dimension that will DISPLAY the image
dimension: product_image {
label: "Product Image"
type: string # The underlying data type is the URL string
sql: ${TABLE}.product_image_url ;; # Fetch the URL
html: | # Using '|' allows for multi-line HTML for readability
{% if value %} {# Check if the URL value is not null/empty #}
<img src="{{ value }}" style="height: 50px; width: auto; max-width: 100px; display: block; margin: auto;" alt="Product Image for {{ product_name._value | escape }}">
{% else %}
<!-- Optional: Display something if no URL is present -->
N/A
{% endif %} ;;
}
}
Explanation:
dimension: product_image: Defines the dimension that will show the image.
label: "Product Image": Sets the column header name in Looker explores/dashboards.
type: string: Even though it displays an image, the underlying data type Looker works with here is the URL string.
sql: ${TABLE}.product_image_url ;;: Tells Looker how to fetch the image URL from your database.
html: ... ;;: This is the key parameter. Looker executes the Liquid templating within it and renders the resulting HTML in the table cell.
{% if value %}: A Liquid check to ensure the URL field (value refers to the result of the sql parameter for this dimension in the current row) is not empty before trying to render an image tag.
<img src="{{ value }}">: The standard HTML image tag. {{ value }} dynamically inserts the URL fetched by the sql parameter for that specific row.
style="...": Crucial! You must control the image size using CSS (style) or HTML attributes (width, height). Otherwise, large images can break your table layout.
height: 50px;: Sets a fixed height.
width: auto;: Lets the width adjust automatically based on the height to maintain aspect ratio.
max-width: 100px;: Prevents the image from becoming excessively wide even if its aspect ratio demands it at 50px height.
display: block; margin: auto;: Centers the image within the table cell (optional styling).
alt="...": Important for accessibility and SEO. It provides alternative text if the image fails to load. Here, it dynamically includes the product name ({{ product_name._value }}) using Liquid referencing another dimension in the same view. The | escape filter ensures any special HTML characters in the name are properly handled.
{% else %}: What to display if the value (URL) is empty or null.
|: Using the pipe character after html: allows you to write multi-line HTML more cleanly without needing quotes on each line.
Example 2: Constructing the URL in LookML
Sometimes, the full URL isn't in the database, but you have parts (like a base path and an image filename or ID).
lookml
view: products {
sql_table_name: public.products ;;
dimension: product_id {
primary_key: yes
type: string # Assuming ID might be alphanumeric
sql: ${TABLE}.product_id ;;
}
dimension: product_image_filename {
type: string
sql: ${TABLE}.image_filename ;; # e.g., 'widget-a.jpg'
}
dimension: product_image {
label: "Product Image"
type: string
# Construct the URL using SQL CONCAT (syntax varies by SQL dialect)
sql: CONCAT('https://cdn.example.com/images/', ${TABLE}.image_filename) ;;
# Or using Liquid templating within the html parameter (less common for full URL construction)
# sql: ${product_image_filename} ;; # Fetch just the filename
html: |
{% assign base_url = 'https://cdn.example.com/images/' %}
{% assign full_url = base_url | append: value %} {# 'value' here is the filename from sql #}
{% if value %} {# Check if filename exists #}
<img src="{{ full_url }}" style="height: 50px; width: auto;" alt="Product Image">
{% else %}
N/A
{% endif %} ;;
}
}
Example 3: Making the Image a Link
You can wrap the <img> tag inside an <a> (anchor) tag to make the image clickable.
lookml
view: products {
# ... other dimensions ...
dimension: product_page_url {
type: string
sql: ${TABLE}.product_url ;; # URL of the product detail page
hidden: yes
}
dimension: image_url_raw {
type: string
sql: ${TABLE}.product_image_url ;;
hidden: yes
}
dimension: product_image_link {
label: "Product"
type: string
sql: ${TABLE}.product_image_url ;; # Need the image URL for the src attribute
html: |
{% if value and product_page_url._value %} {# Check image URL ('value') and link URL exist #}
<a href="{{ product_page_url._value }}" target="_blank"> {# Link to product page, opens in new tab #}
<img src="{{ value }}" style="height: 50px; width: auto; max-width: 100px;" alt="Product Image">
</a>
{% elsif value %} {# Only image URL exists, show image without link #}
<img src="{{ value }}" style="height: 50px; width: auto; max-width: 100px;" alt="Product Image">
{% else %}
<!-- No image URL -->
N/A
{% endif %} ;;
}
}
Key Considerations:
Image Size & Performance: Always constrain image dimensions using style or width/height attributes. Loading many large images can significantly slow down dashboard/explore loading.
Styling: Use inline style attributes for CSS. Looker doesn't easily support external CSS files for table cell content.
Broken Links: If the URL is invalid or the image is unavailable, users will see a broken image icon. The alt text becomes important here.
Security (CORS): The user's browser fetches the image directly from the URL. If the image server has strict Cross-Origin Resource Sharing (CORS) policies, the browser might block the image from loading within the Looker domain. Ensure the image hosting allows requests from your Looker instance's domain or is configured for public access.
HTTPS: Use https URLs for images whenever possible, especially if your Looker instance runs on https. Mixed content (http images on an https page) can cause browser warnings or blocked content.
Liquid Syntax: Pay attention to {{ value }} (refers to the dimension's own value) vs. {{ other_dimension_name._value }} (refers to another dimension's value in the same row).
Choose the example that best fits how your image URLs are stored or generated. Remember to adjust table names, column names, and styling to match your specific needs.
User
do it in the dashboard by using markdown
Assistant
Okay, displaying a static image from a URL directly on a Looker dashboard (not within an Explore visualization) is typically done using a Text Tile and leveraging its Markdown/HTML rendering capabilities.
You won't use LookML directly for this dashboard tile itself, but rather the dashboard editing interface.
Here's how to do it:
Go to your Dashboard: Navigate to the Looker dashboard where you want to add the image.
Enter Edit Mode: Click the three-dot menu (⋮) in the upper-right corner of the dashboard and select "Edit dashboard".
Add a Text Tile:
Click "Add" or "Add Tile" (the exact wording might vary slightly based on your Looker version).
Choose "Text" from the options.
Add the Image using HTML:
A configuration window for the new text tile will appear. You'll see fields for "Title" (optional) and "Body" (where you put your content).
In the Body section, you can directly insert an HTML <img> tag. Looker's text tiles render basic HTML.
<img src="...": The core HTML tag for images. Replace "YOUR_IMAGE_URL_HERE" with the actual public URL of your image.
alt="...": Important for accessibility. Provides alternative text if the image cannot be loaded or for screen readers. Describe the image concisely.
User
i only want the upper 50% of the image
Assistant
Okay, you can achieve this effect—showing only the top 50% of an image—within a Looker dashboard Text Tile by using CSS, specifically the clip-path property or by placing the image within a container with overflow: hidden.
Here are two methods using HTML/CSS within the Body of a Text Tile:
Method 1: Using clip-path (Recommended & More Direct)
This method directly tells the browser to only render a specific portion of the image element.
Edit your Dashboard and add/edit a Text Tile.
In the Body section, use the following HTML structure:
html
<!-- Optional wrapper for centering -->
<div style="text-align: center;">
<img
src="YOUR_IMAGE_URL_HERE"
alt="Top half of [Your Image Description]"
style="
/* --- Basic Styling & Sizing --- */
display: block; /* Adjusts spacing, helps centering */
margin-left: auto; /* Centers the image if display: block */
margin-right: auto; /* Centers the image if display: block */
max-width: 100%; /* Makes image responsive within the tile */
height: auto; /* Maintains aspect ratio */
/* --- Key Part: Clipping --- */
/* Clips the image: top, right, bottom, left */
/* inset(0 0 50% 0) means:
- 0 from the top
- 0 from the right
- 50% (of the image's height) from the BOTTOM
- 0 from the left
This effectively hides the bottom half. */
clip-path: inset(0 0 50% 0);
/* Optional: Vendor prefix for slightly older WebKit browsers (Safari, Chrome) */
-webkit-clip-path: inset(0 0 50% 0);
"
>
</div>
Explanation:
style="...": (Optional but highly recommended) Controls the appearance and size.
max-width: 100%;: Ensures the image doesn't overflow the width of the text tile. It will scale down if needed.
height: auto;: Maintains the image's aspect ratio when the width is adjusted.
display: block; margin-left: auto; margin-right: auto;: A common way to center the image within the tile.
max-height: 100px;: (Example) You can set a maximum pixel height if desired. Adjust the value as needed.
You can also use fixed widths/heights like width: 200px; height: 50px;, but be aware this might distort the image if the aspect ratio doesn't match. Using max-width and height: auto is generally better for responsiveness.
<div style="text-align: center;">...</div>: Another way to center the image by wrapping it in a div container.
Configure Title (Optional): Add a Title to your text tile if desired.
Save the Tile: Click "Save" or "Done" on the tile configuration.
Position and Resize the Tile: Drag and resize the new text tile on your dashboard grid as needed.
Save the Dashboard: Click "Save" or "Done" on the main dashboard editing bar.
Key Considerations:
Public URL: The image URL must be publicly accessible on the internet. Looker (or rather, the user's browser viewing the dashboard) needs to be able to fetch it without authentication.
HTTPS: Use https:// URLs if possible, especially if your Looker instance uses HTTPS, to avoid mixed-content warnings in browsers.
CORS: While less common for simple image display, be aware that the server hosting the image might have Cross-Origin Resource Sharing (CORS) policies. If very strict, it could potentially prevent the image from loading in the context of your Looker domain, but this is rare for standard image hosting.
Static Image: This method is for displaying a static image defined by the URL you hardcode in the text tile. It won't dynamically change based on dashboard filters or data unless you manually edit the tile again. (If you need a dynamic image based on data, you'd use the LookML html parameter method within a visualization tile, as described previously).
Sizing: Pay attention to the style attribute to control the image size so it fits nicely within the tile and dashboard layout.
src="...": Replace with your image URL.
alt="...": Important for accessibility. Describe the image and maybe note that it's cropped.
max-width: 100%; height: auto;: Standard practice to make the image scale nicely within the tile.
clip-path: inset(0 0 50% 0);: This is the core CSS rule. inset() defines a rectangular clipping region. The values correspond to offsets from the top, right, bottom, and left edges, respectively. By setting the bottom offset to 50%, you clip away the bottom half of the image.
-webkit-clip-path: Included for better compatibility with slightly older versions of Safari and Chrome, although clip-path is widely supported now.
Centering (<div> and display: block; margin: auto;): These are optional for positioning the resulting clipped image within the text tile.
Method 2: Using a Container with overflow: hidden
This method creates a container <div> that has a specific height (which will be the height of the visible top portion) and hides any part of the image that overflows that container.
Edit your Dashboard and add/edit a Text Tile.
In the Body section, use this HTML:
html
<!-- Container Div -->
<div style="
height: 100px; /* SET THE DESIRED VISIBLE HEIGHT HERE */
width: 200px; /* SET THE DESIRED VISIBLE WIDTH HERE (or use max-width: 100%) */
overflow: hidden; /* Hides anything outside this div's bounds */
position: relative; /* Establishes positioning context for the image */
margin: auto; /* Optional: centers the container div itself */
">
<!-- The Image -->
<img
src="YOUR_IMAGE_URL_HERE"
alt="Top part of [Your Image Description]"
style="
display: block;
position: absolute; /* Position relative to the container */
top: 0; /* Align image top to container top */
left: 0; /* Align image left to container left */
width: 100%; /* Make image fill container width */
height: auto; /* Let height adjust proportionally */
/* We don't set image height directly, it will overflow */
/* 'overflow: hidden' on the parent does the cropping */
"
>
</div>
Explanation:
Container <div>:
height: 100px;: Crucially, you set the explicit height you want the visible portion to have. This won't automatically be 50% of the original image unless you calculate it based on the original image's aspect ratio and the width you set. This method gives you a fixed-size viewport onto the image.
width: 200px; or max-width: 100%;: Define the width of the visible area.
overflow: hidden;: This hides the parts of the <img> tag that extend beyond the container's dimensions.
position: relative;: Needed so the position: absolute; on the image works correctly relative to this container.
margin: auto;: Centers the container itself within the text tile.
Image <img>:
position: absolute; top: 0; left: 0;: Positions the image at the top-left corner inside the container.
width: 100%; height: auto;: The image scales to the container's width, and its height adjusts. Since the container has overflow: hidden and a fixed height, only the top portion of the scaled image that fits within the container's height will be visible.
Which method to choose?
Use Method 1 (clip-path) if you specifically want to show the top 50% of the original image's height, regardless of the final display size. It's more semantically correct for this specific request.
Use Method 2 (Container with overflow: hidden) if you want to define a fixed-size window (e.g., exactly 100px tall) and show whatever top portion of the image fits into that window when scaled to the container's width.
Remember to replace "YOUR_IMAGE_URL_HERE" and adjust alt text and dimensions/styling as needed.