# Problem dynamically render image in canvas

**URL:** <https://discuss.elastic.co/t/problem-dynamically-render-image-in-canvas/196266>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [August 22, 2019, 7:59am UTC](https://discuss.elastic.co/t/problem-dynamically-render-image-in-canvas/196266 "2019-08-22T07:59:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LacioDrom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laciodrom/32/49350_2.png) [@LacioDrom](https://discuss.elastic.co/u/LacioDrom)\
**Post date:** [August 22, 2019, 7:59am UTC](https://discuss.elastic.co/t/problem-dynamically-render-image-in-canvas/196266/1 "2019-08-22T07:59:58Z")

</div>

Hi all,

I'm new with canvas expression language, so probably my question is trivial: I'm trying to dinamically render an image in a canvas using switch statement, but I've got this error:

![Immagine](https://us1.discourse-cdn.com/elastic/original/3X/c/6/c65f1961f6b21ce1a33ae4f4993fb8ae160c5472.png)

Here my code:

```
 filters
    | essql query="SELECT value FROM \"dummydata\" as Value ORDER BY timestamp DESC LIMIT 1"
    | math "value" 
    | revealImage origin="bottom" image={asset 
    | switch 
    {case if={compare eq to=1} then="asset-408ac6c1-42d8-4ce5-87f3-7bf90bc26a6d"}
    {case if={compare eq to=0} then="asset-3812f249-cefe-4c90-9568-6d61477b7293"}
    default="asset-df5a0609-c5fa-4c3e-bc2e-d539b38749a8"
    }
     emptyImage={asset 

    | switch 
    {case if={compare eq to=1} then="asset-408ac6c1-42d8-4ce5-87f3-7bf90bc26a6d"}
    {case if={compare eq to=0} then="asset-3812f249-cefe-4c90-9568-6d61477b7293"}
    default="asset-df5a0609-c5fa-4c3e-bc2e-d539b38749a8"
    }
    | render

```

Any hint about the issue?

Thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [August 22, 2019, 11:27pm UTC](https://discuss.elastic.co/t/problem-dynamically-render-image-in-canvas/196266/2 "2019-08-22T23:27:34Z")

</div>

The `asset` in `...image={asset | switch...` expects an [`id` argument](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#asset_fn). Although I think you could just remove `asset |` and use `image={switch ...`.

---

<div class="post-metadata">

**Author:** ![LacioDrom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/laciodrom/32/49350_2.png) [@LacioDrom](https://discuss.elastic.co/u/LacioDrom)\
**Post date:** [August 23, 2019, 8:25am UTC](https://discuss.elastic.co/t/problem-dynamically-render-image-in-canvas/196266/3 "2019-08-23T08:25:31Z")

</div>

Hi @nickpeihl, thanks for the reply.  
I found the problem...I've just substituted `asset |` with `asset {....}`, now it works fine:

```
| essql query="SELECT value FROM \"dummydata\" as Value ORDER BY timestamp DESC LIMIT 1"
| math "value" 
| revealImage origin="bottom" image={asset {
 switch 
{case if={compare eq to=1} then="asset-408ac6c1-42d8-4ce5-87f3-7bf90bc26a6d"}
{case if={compare eq to=0} then="asset-3812f249-cefe-4c90-9568-6d61477b7293"}
default="asset-df5a0609-c5fa-4c3e-bc2e-d539b38749a8"
}}
 emptyImage={asset {

switch 
{case if={compare eq to=1} then="asset-408ac6c1-42d8-4ce5-87f3-7bf90bc26a6d"}
{case if={compare eq to=0} then="asset-3812f249-cefe-4c90-9568-6d61477b7293"}
default="asset-df5a0609-c5fa-4c3e-bc2e-d539b38749a8"
}}
| render
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 20, 2019, 8:25am UTC](https://discuss.elastic.co/t/problem-dynamically-render-image-in-canvas/196266/4 "2019-09-20T08:25:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
