마크다운 텍스트 타일에 이미지 URL을 하드 코딩하여 Looker 대시보드에 이미지를 추가할 수 있습니다. 하지만 텍스트 카드의 이미지는 정적이며 결과에 따라 업데이트되지 않습니다.
사용자가 선택한 필터 값에 따라 대시보드 이미지를 동적으로 변경하려면 어떻게 해야 할까요?
이 권장사항 페이지에서는 Liquid 및 html 매개변수를 사용하여 동적 대시보드 이미지를 구현하는 방법을 보여줍니다.
해결 방법
다음 솔루션은 가상의 전자상거래 데이터 세트의 상태를 나타내는 users.state라는 필드가 포함된 전자상거래 데이터 세트를 기반으로 합니다.
dimension: state {
type: string
sql: ${TABLE}.state ;;
}
사용자가 대시보드 결과를 필터링하기로 선택한 상태를 기준으로 업데이트되는 대시보드에 상태 플래그 이미지를 표시한다고 가정해 보겠습니다.
동적 대시보드 이미지를 만들려면 다음 세 단계를 완료해야 합니다.
LookML에서 이미지 크기를 만듭니다.
동적 이미지 대시보드 타일을 만듭니다.
대시보드 필터 및 최종 터치를 추가합니다.
1단계: LookML에서 이미지 크기 만들기
LookML에서 이미지 크기를 만들려면 다음 안내를 따르세요.
먼저 프로젝트로 이동하고 이미지를 추가할 측정기준이 포함된 파일을 확인합니다. 그런 다음 해당 필드를 기반으로 새 측정기준, 특히 이미지 표시에 사용할 측정기준을 만듭니다.
이미지를 표시할 각 값에 value 변수를 사용하여 Liquid {% if %} 조건문을 정의하는 html 매개변수를 추가합니다.
예를 들어 다음 state_flag_image 측정기준은 state 값이 "California", "New York", "Colorado" 또는 "Illinois"일 때 지정된 이미지(html <img> 태그 사용)를 표시하는 조건을 설정합니다. 다른 모든 주에서는 '사용 가능한 이미지 없음' 아이콘을 표시할 수 있습니다.
이미지를 표시할 각 값에 대한 값 조건을 만듭니다. 또는 시각화에 이미지를 추가하는 방법 커뮤니티 게시물에 설명된 대로 value Liquid 변수를 사용해 동적 이미지 필드를 만들 수도 있습니다.
그런 다음 이미지 크기에 대한 대시보드 타일을 만들 수 있습니다.
2단계: 동적 이미지 대시보드 타일 만들기
이제 이미지 크기(state_flag_image)를 만들었으므로 동적 이미지 대시보드 타일이 되는 Explore를 빌드할 수 있습니다.
다음 기준으로 Explore를 빌드합니다.
원래 측정기준(이 경우 state)에 대한 필터를 추가합니다. 필터를 원하는 값으로 설정합니다(구체적인 필터 값이 선택되지 않았으므로 주 플래그는 '사용 가능한 이미지 없음' 이미지를 표시합니다.) 이 필터 값은 사용자가 대시보드 필터에 선택한 내용에 따라 업데이트됩니다.
이미지 크기(이 경우 state_flag_image)와 이미지를 결정하는 쿼리에 필요할 수 있는 다른 측정기준(예: 날짜를 고려할 경우 날짜 포함, 등)을 선택합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-31(UTC)"],[],[],null,["# Create a dynamic dashboard image with Liquid and HTML\n\nYou can add images to Looker dashboards by hard-coding an image URL in a Markdown [text tile](/looker/docs/using-markdown-in-text-tiles#images). However, images in text tiles are static and will not update based on results.\nWhat if you want a dashboard image to dynamically change based on a user-selected filter value?\n\n\nThis Best Practices page demonstrates how to achieve a dynamic dashboard image using [Liquid](/looker/docs/liquid-variable-reference) and the [`html` parameter](/looker/docs/reference/param-field-html).\n\nThe solution\n------------\n\n\nThe following solution is based on an e-commerce data set that includes a field called `users.state`, representing the states in a hypothetical ecommerce data set: \n\n```\ndimension: state {\n type: string\n sql: ${TABLE}.state ;;\n}\n```\n\n\nSay that you want to display the image of a state's flag on a dashboard that will update based on the state by which a user chooses to filter the dashboard results.\n\n\nThere are three steps that you need to complete to create the dynamic dashboard image:\n\n1. Create an image dimension in LookML.\n2. Create a dynamic image dashboard tile.\n3. Add dashboard filters and final touches.\n\n\u003cbr /\u003e\n\n### Step 1: Create an image dimension in LookML\n\n\nTo create an image dimension in LookML:\n\n1. 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.\n2.\n Add an `html` parameter for defining a Liquid [`{% if %}` conditional statement](/looker/docs/liquid-variable-reference#basic_examples) with the [`value`](/looker/docs/liquid-variable-reference#liquid_variable_definitions) variable, for each value for which you want to display an image.\n\n\n For example, the following `state_flag_image` dimension establishes a condition for displaying the specified images (with `html \u003cimg\u003e `tags) when the value of `state` is `\"California\"`, `\"New York\"`, `\"Colorado\"`, or `\"Illinois\"`. For all other states, you can display a \"no image available\" icon: \n\n ```\n dimension: state_flag_image {\n type: string\n sql: ${state} ;;\n html:\n {% if state._value == \"California\" %}\n \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/0/01/Flag_of_California.svg\" height=\"170\" width=\"255\"\u003e\n {% elsif state._value == \"New York\" %}\n \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Flag_of_New_York.svg/1200px-Flag_of_New_York.svg.png\" height=\"170\" width=\"255\"\u003e\n {% elsif state._value == \"Colorado\" %}\n \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Flag_of_Colorado.svg/255px-Flag_of_Colorado.svg.png\" height=\"170\" width=\"255\"\u003e\n {% elsif state._value == \"Illinois\"%}\n \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/0/01/Flag_of_Illinois.svg/1200px-Flag_of_Illinois.svg.png\" height=\"170\" width=\"255\"\u003e\n {% else %}\n \u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/1024px-No_image_available.svg.png\" height=\"170\" width=\"170\"\u003e\n {% endif %} ;;\n }\n \n ```\n3. Create a value condition for each value for which you would like to display an image. Alternatively, you can create a dynamic image field using the `value` Liquid variable, as described in the [How to add images to visualizations](https://community.looker.com/technical-tips-tricks-1021/how-to-add-images-to-visualizations-30238) Community post.\n\n\nNext, you can create a dashboard tile for the image dimension.\n\n### Step 2: Create a dynamic image dashboard tile\n\n\nNow that the image dimension (`state_flag_image`) has been created, you can build an Explore that will become the dynamic image dashboard tile.\n\nBuild your Explore with the following criteria:\n\n- Add a filter for the original dimension (in this case, `state`). Set the filter for any value (the state flag 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.\n- Select the image dimension (in this case, `state_flag_image`) 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.).\n- Change the [row limit](/looker/docs/filtering-and-limiting#limiting_data) to one row.\n- Change the visualization type to a [single value visualization](/looker/docs/single-value-options) and [hide](/looker/docs/creating-visualizations#specifying_lookml_fields_to_include_in_the_visualization) any other columns except the image dimension (`state_flag_image`).\n\n\nYour Explore will display the first image result in the single value visualization rendered in the **Visualization** panel. The display image will change based on the filter value the user selects on the final dashboard:\n\n\nSave the Explore to a dashboard as a [tile](/looker/docs/creating-user-defined-dashboards#adding_query_tiles_from_an_explore).\n\n### Step 3: Add dashboard filters and final touches\n\n\nNow you 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 selection.\n\n\nFrom the dashboard's edit mode, [create the filter](/looker/docs/filters-user-defined-dashboards#adding_dashboard_filters):\n\n- Open the [**Add filter window**](/looker/docs/filters-user-defined-dashboards#the_add_filter_window)\n- Select the field to filter by. The filter field should be the dimension on which the image dimension is based. In the case of this example, the field for the filter will be **state**.\n- Select the image tile from Step 2 on the **Tiles to Update** tab.\n- Select the original dimension (**state** in this case) in the inline **Field to Filter** drop-down menu.\nSelect other tiles to update as desired.\n- [Customize](/looker/docs/filters-user-defined-dashboards#customizing_filter_configuration) the filter as desired. If you select the **Advanced** [control option](/looker/docs/filters-user-defined-dashboards#using_advanced_controls), make sure to deselect the **Allow multiple filter values** option, which is automatically enabled for the **Advanced** control option.\n\n\nNow, the image tile will update with the user filter selection.\n\n\nWhen a user chooses to filter by \"California\", the dashboard will display the state flag and data for the state of California:\n\n\nWhen a user chooses to filter by \"Colorado\", the dashboard will display the state flag and data for the state of Colorado:"]]