# API addwidget()

**URL:** <https://discourse.nodered.org/t/api-addwidget/13604>\
**Category:** Dashboard\
**Created:** [23 July 2019 11:13 UTC](https://discourse.nodered.org/t/api-addwidget/13604 "2019-07-23T11:13:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Landry25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/landry25/32/10355_2.png) [@Landry25](https://discourse.nodered.org/u/Landry25)\
**Post date:** [23 July 2019 11:13 UTC](https://discourse.nodered.org/t/api-addwidget/13604/1 "2019-07-23T11:13:37Z")

</div>

I'm using the API addwidget() to create a dashboard node (graph) , and I don't know why but when I re-deploy my flow, or when I refresh the page , I have the last point which seems to be sent again by the backend . So I would know if it's possible to listen specific event (similar to "nodes-started") with this addwidget() API, to clear the graph after a redeploy.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [23 July 2019 16:42 UTC](https://discourse.nodered.org/t/api-addwidget/13604/2 "2019-07-23T16:42:00Z")

</div>

Hi @Landry25,

Can't you do that in the initController function?

```auto
ui.addWidget({  
    ...
    initController: function($scope, events) { .. }
    …
})

```

Bart

---

<div class="post-metadata">

**Author:** ![Landry25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/landry25/32/10355_2.png) [@Landry25](https://discourse.nodered.org/u/Landry25)\
**Post date:** [24 July 2019 11:32 UTC](https://discourse.nodered.org/t/api-addwidget/13604/3 "2019-07-24T11:32:19Z")

</div>

Thank you. I'm not sure to understand how it's working, do you have some examples ?

I'm afraid also this initcontroller will be called too early , and the points are sent after initialization of the graphical part. But I have a to try.

Landry

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 July 2019 18:17 UTC](https://discourse.nodered.org/t/api-addwidget/13604/4 "2019-07-24T18:17:22Z")

</div>

> [@Landry25](#):
>
> do you have some examples

The number of UI nodes is reather rather limited:

- [GitHub - Adorkable/node-red-contrib-ui-led: A simple LED status indicator for the Node-RED Dashboard](https://github.com/Adorkable/node-red-contrib-ui-led)
- [GitHub - hotNipi/node-red-contrib-ui-level: A linear level type widget to the Node-RED dashboard](https://github.com/hotNipi/node-red-contrib-ui-level)
- [GitHub - node-red/node-red-ui-nodes: Additional nodes for Node-RED Dashboard](https://github.com/node-red/node-red-ui-nodes)
- [GitHub - bartbutenaers/node-red-contrib-ui-heatmap: A Node Red node to show a heat map](https://github.com/bartbutenaers/node-red-contrib-ui-heatmap)
- …

> [@Landry25](#):
>
> and the points are sent after initialization of the graphical part

This is not clear to me. I propose you share some of your code, so people can try to understand what is going wrong. Otherwise we can only guess what is going wrong. E.g. do you store the graph points on the Angular scope?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [24 July 2019 19:41 UTC](https://discourse.nodered.org/t/api-addwidget/13604/5 "2019-07-24T19:41:08Z")

</div>

> [@Landry25](#):
>
> to clear the graph after a redeploy

Do you mean every deploy and no matter if your widget configuration is changed or not? I don't think it is good idea to create such connection between absolutely not related events. Look and feel and behavior of graphical widgets should depend on configuration and incoming data only.

---

<div class="post-metadata">

**Author:** ![Landry25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/landry25/32/10355_2.png) [@Landry25](https://discourse.nodered.org/u/Landry25)\
**Post date:** [25 July 2019 08:05 UTC](https://discourse.nodered.org/t/api-addwidget/13604/6 "2019-07-25T08:05:20Z")

</div>

Dear all,

I will try to better explain my issue. You can easily reproduce it with a very basic flow made of on inject node and one linear graph. In the inject node you create a message send to the graph to display some points. You deploy it, you have a graph generated, everything is perfect.  
Then you break the link between the inject node and the graph, you redeploy it, you have still points in the graph (last points sent previously ).  
Is it a bug or feature to have some "persistent data" ? How can I remove this behavior ?

It's not a question of cache not cleaned because I see the request coming from the runtime when we redeploy the second time .

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 July 2019 08:22 UTC](https://discourse.nodered.org/t/api-addwidget/13604/7 "2019-07-25T08:22:30Z")

</div>

Have you selected Full Deploy for the deploy button? Otherwise the chart node will not be restarted so it will still have the points stored.

---

<div class="post-metadata">

**Author:** ![Landry25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/landry25/32/10355_2.png) [@Landry25](https://discourse.nodered.org/u/Landry25)\
**Post date:** [25 July 2019 08:49 UTC](https://discourse.nodered.org/t/api-addwidget/13604/8 "2019-07-25T08:49:59Z")

</div>

Yes it's a full deploy

---

<div class="post-metadata">

**Author:** ![Thierry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thierry/32/8654_2.png) [@Thierry](https://discourse.nodered.org/u/Thierry)\
**Post date:** [25 July 2019 10:47 UTC](https://discourse.nodered.org/t/api-addwidget/13604/9 "2019-07-25T10:47:12Z")

</div>

@Landry25 @BartButenaers Indeed I do confirm the behavior whatever the widget used : the standard ones from the dashboard, the @BartButenaers ones, or custom ...  
Actually after a (re)deploy the runtime is sending back the last data (from previous deploy) over the websocket to the dashboard hence the concerned widgets are updated with the last data from previous deploy.  
Don't know how to avoid the runtime to send back the data ...  
Not sure either we can change this behavior with initController as the data are coming after initContoller has been executed ... the only "dirty" solution might be to cancel the data once they are received in a setTimeout in initController.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2019 11:23 UTC](https://discourse.nodered.org/t/api-addwidget/13604/10 "2019-07-25T11:23:03Z")

</div>

I think that if you set storeFrontEndInputAsState as false then it won’t save widget data, so would then have nothing to restore.

---

<div class="post-metadata">

**Author:** ![Landry25](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/landry25/32/10355_2.png) [@Landry25](https://discourse.nodered.org/u/Landry25)\
**Post date:** [25 July 2019 11:56 UTC](https://discourse.nodered.org/t/api-addwidget/13604/11 "2019-07-25T11:56:35Z")

</div>

I already set the attribute storeFrontEndInputAsState as false in my widget and the behavior is not modified.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 July 2019 12:51 UTC](https://discourse.nodered.org/t/api-addwidget/13604/12 "2019-07-25T12:51:18Z")

</div>

@dceejayIs the described behaviour what you would expect for the dashboard chart? I would have expected a Full Deploy to have cleared it.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2019 13:22 UTC](https://discourse.nodered.org/t/api-addwidget/13604/13 "2019-07-25T13:22:50Z")

</div>

Honestly can’t recall. Still on vacation

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 July 2019 13:25 UTC](https://discourse.nodered.org/t/api-addwidget/13604/14 "2019-07-25T13:25:53Z")

</div>

Yes of course, sorry.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2019 13:30 UTC](https://discourse.nodered.org/t/api-addwidget/13604/15 "2019-07-25T13:30:17Z")

</div>

I think only a stop start will clear it, not a deploy of any sort.

---

<div class="post-metadata">

**Author:** ![Thierry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thierry/32/8654_2.png) [@Thierry](https://discourse.nodered.org/u/Thierry)\
**Post date:** [25 July 2019 14:28 UTC](https://discourse.nodered.org/t/api-addwidget/13604/16 "2019-07-25T14:28:12Z")

</div>

Few tests on my side, I do confirm :

- storeFrontEndInputAsState as no effect on resending data at deploy either on my custom node nor on contrib ui nodes from npm (at least ui\_level for @BartButenaers)
- only stop start clear it as @dceejay said

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 July 2019 14:36 UTC](https://discourse.nodered.org/t/api-addwidget/13604/17 "2019-07-25T14:36:46Z")

</div>

The workaround is to send the chart an empty array on deploy.

---

<div class="post-metadata">

**Author:** ![Thierry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thierry/32/8654_2.png) [@Thierry](https://discourse.nodered.org/u/Thierry)\
**Post date:** [25 July 2019 14:40 UTC](https://discourse.nodered.org/t/api-addwidget/13604/18 "2019-07-25T14:40:40Z")

</div>

Indeed but then it seems a bit weird to me to have such storeFrontEndInputAsState boolean with no effect

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2019 19:32 UTC](https://discourse.nodered.org/t/api-addwidget/13604/19 "2019-07-25T19:32:36Z")

</div>

I would need to look at the code, but I suspect the bit i forgot is where it says FrontEnd. Ie it optionally stores state coming from the ui. I’d guess that indeed it stores everything coming from the back end, ie sent to the node.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [25 July 2019 19:37 UTC](https://discourse.nodered.org/t/api-addwidget/13604/20 "2019-07-25T19:37:50Z")

</div>

Comments in `index.js` says clearly

```auto
       * [storeFrontEndInputAsState] - boolean (default true).
             If true, any message received from front-end is stored as state

```

[Next page](https://discourse.nodered.org/t/api-addwidget/13604.md?page=2)
