# Hey I created canvas widget using below script but widgets failed to load in 8.4.2 Version

**URL:** https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782
**Category:** Kibana
**Tags:** canvas
**Created:** [October 31, 2022, 7:12am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782 "2022-10-31T07:12:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Nabeel\_Ahmed\_NAK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nabeel_ahmed_nak/32/133673_2.png) [@Nabeel\_Ahmed\_NAK](https://discuss.elastic.co/u/Nabeel_Ahmed_NAK)
#### Post date: [October 31, 2022, 7:12am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/1 "2022-10-31T07:12:22Z")

</div>

I'm facing an issue of failed loading of widgets and even assets like images when elasticsearch moves to 8.3.2 to 8.4.2.

I have two kinds of widgets like Status count and percentage of status (Also handle divide by zero) in canvas  
**1st Type of Query:**

```auto
kibana
| selectFilter
| essql 
  query="SELECT COUNT(DISTINCT Hex_Hostname) AS UP FROM \"heartbeat-*\" WHERE monitor.name = 'Core Switch' AND monitor.status = 'up' AND \"@timestamp\" > NOW() - INTERVAL 5 MINUTES"
| math "UP"
| metric "UP" 
  metricFont={font size=48 family="'Open Sans', Helvetica, Arial, sans-serif" color={if {all {gt 0}} then="#7BBB58" else="#C30721"} align="center" lHeight=48} 
  labelFont={font size=14 family="'Open Sans', Helvetica, Arial, sans-serif" color={if {all {gt 0}} then="#7BBB58" else="#C30721"} align="center"} metricFormat="0,0.[000]"
| render

```

**2nd Query**

```auto
kibana

| selectFilter

| essql

query="SELECT COUNT(DISTINCT Hex_Hostname) AS UP FROM \"heartbeat-*\" WHERE monitor.name = 'Access Points' AND monitor.status = 'up' AND \"@timestamp\" > NOW() - INTERVAL 5 MINUTES"

| var_set name="UPvar" value={getCell "UP"}

| filters

| essql

query="SELECT COUNT(DISTINCT Hex_Hostname) AS total FROM \"heartbeat-*\" WHERE monitor.name = 'Access Points' AND \"@timestamp\" > NOW() - INTERVAL 5 MINUTES"

| var_set name="totalvar" value={getCell "total"}

| if {any {getCell "total" | compare "lt" to=0.01}} then={var_set name="totalvar" value=1}

| math {string {var "UPvar"} " / " {var "totalvar"}}

| metric "Access Point"

metricFont={font align="center" color={if {all {gt 0.95}} then="#7BBB58" else="#EFE634"} family="'Open Sans', Helvetica, Arial, sans-serif" italic=false size=36 underline=false weight="normal"}

labelFont={font size=14 family="'Open Sans', Helvetica, Arial, sans-serif" color={if {all {gt 0.95}} then="#7bbb58" else="#EFE634"} align="center"} metricFormat="0,0%"

| render

```

Here 2 screenshots available when I did refresh 2 times.

Some widgets works and some are not each time I refresh.

 ![chrome_4gWSOfaFLQ](https://us1.discourse-cdn.com/elastic/original/3X/7/7/777aeda864986577a43b59b6688325a188823409.png)  
 ![chrome_OSBaEEqU2u](https://us1.discourse-cdn.com/elastic/original/3X/2/5/25f537ce3e78d5dcf8aac88c2b58adb510ae7ebd.png)

---

<div class="post-metadata">

### Author: ![JLeysens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jleysens/32/67404_2.png) [@JLeysens](https://discuss.elastic.co/u/JLeysens)
#### Post date: [October 31, 2022, 10:18am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/2 "2022-10-31T10:18:10Z")

</div>

Hello @Nabeel_Ahmed_NAK !

Would you mind sharing the error messages that are being returned for those visualisations? They should appear when you click on them.

---

<div class="post-metadata">

### Author: ![Nabeel\_Ahmed\_NAK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nabeel_ahmed_nak/32/133673_2.png) [@Nabeel\_Ahmed\_NAK](https://discuss.elastic.co/u/Nabeel_Ahmed_NAK)
#### Post date: [October 31, 2022, 11:42am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/3 "2022-10-31T11:42:43Z")

</div>

Here are some screenshots of widgets with errors.

 ![chrome_zXl5uzFMam](https://us1.discourse-cdn.com/elastic/original/3X/d/7/d7221b3274220bc06eb820226852096086c26405.png)

 ![chrome_bXkOOnBLhC](https://us1.discourse-cdn.com/elastic/original/3X/7/4/742081d2ce0d7971e71a5235d320613e3fa98179.png)

Appreaciated

---

<div class="post-metadata">

### Author: ![Nabeel\_Ahmed\_NAK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nabeel_ahmed_nak/32/133673_2.png) [@Nabeel\_Ahmed\_NAK](https://discuss.elastic.co/u/Nabeel_Ahmed_NAK)
#### Post date: [October 31, 2022, 11:45am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/4 "2022-10-31T11:45:02Z")

</div>

HI @JLeysens  
The issue I'm facing here is sometimes it will load properly but most of the time widgets are not loading.

Thanks

---

<div class="post-metadata">

### Author: ![JLeysens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jleysens/32/67404_2.png) [@JLeysens](https://discuss.elastic.co/u/JLeysens)
#### Post date: [October 31, 2022, 11:53am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/5 "2022-10-31T11:53:12Z")

</div>

As time passes your datatable sometimes has data other times not (since you are looking at the last 5 minutes based on your query this is probably a smallish sample set).

See this solution for handling a potentially empty datatable:

> [@Handling an empty datatable](https://discuss.elastic.co/t/handling-an-empty-datatable/186963/2):
>
> Finally figured this one out. I replaced the line: math "mean(percentage)" with: if {rowCount | eq 0} then=0 else={math "mean(percentage)"} If the datatable is not empty, then it returns the average of the "percentage" column, otherwise it returns an "average" value of 0. Now I no longer get the error triangle at runtime of the canvas.

You should be able to prevent the empty datatable from causing issues for your `getCell` call too (note: `getCell` defaults to using row `0` if now value is provided, [see the docs](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#getCell_fn))

---

<div class="post-metadata">

### Author: ![Nabeel\_Ahmed\_NAK](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nabeel_ahmed_nak/32/133673_2.png) [@Nabeel\_Ahmed\_NAK](https://discuss.elastic.co/u/Nabeel_Ahmed_NAK)
#### Post date: [October 31, 2022, 12:20pm UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/6 "2022-10-31T12:20:00Z")

</div>

Hi @JLeysens

Here the issue is not handling the errors. I issue is that it was working properly when I created it at V8.2.3 but after upgrading version canvas not able to load widgets as well as images that were stored in assets ? So do images have the issue of datatable while it was store in assets?

I was monitoring data every 2m from heartbeat so data is their but not loading properly

Is there any thing that I can do to avoid loading issues.

I don't want to use exception handling while elasticsearch has data but loading it.

Thanks

---

<div class="post-metadata">

### Author: ![JLeysens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jleysens/32/67404_2.png) [@JLeysens](https://discuss.elastic.co/u/JLeysens)
#### Post date: [October 31, 2022, 12:31pm UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/7 "2022-10-31T12:31:40Z")

</div>

Hm, sounds like two different issues...

From your screenshots it definitely looks like you need to do error handling, this would have also thrown in previous versions of Canvas.

Canvas assets not loading between versions sounds like a bug. Would you share some screenshots of that specific issue along with logs/error messages from the UI, console and network tab. We may need to file a bug report.

---

<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: [November 27, 2022, 12:35pm UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/8 "2022-11-27T12:35:08Z")

</div>



---

<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: [December 25, 2022, 9:36am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/9 "2022-12-25T09:36:31Z")

</div>



---

<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: [January 22, 2023, 9:36am UTC](https://discuss.elastic.co/t/hey-i-created-canvas-widget-using-below-script-but-widgets-failed-to-load-in-8-4-2-version/317782/10 "2023-01-22T09:36:40Z")

</div>

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