Skip to content

Add buttons and selectors to a panel ​

A panel is also where the operators act: inspect a product now, start or stop the line, choose a setting. Each of those is a widget that sends a message into the flow when it is used. In this guide you add three to the panel of a biscuit line: a button, a button that asks for confirmation and a drop-down list.

What you will learn

  • How a button starts something in the flow
  • How to ask the operator to confirm before acting
  • How to let the operator choose an option

Before you start

You need a panel page; here the one built in Show inspection results on a panel, «Biscuit line», with a second group, «Controls», for the controls. The flow has what the controls will drive: a from-dataset node «one pack» that brings one pack at random, a function node «start or stop» that turns true and false into the start and stop of the stream, and a change node «remember» that keeps a value in the flow context.

1. Add a button ​

Type ui-button in «filter nodes», drag the «button» node onto the workspace and wire it to «one pack». Open it, choose the group «Controls», and write the «Label», here «Inspect one pack». «Icon» takes a Material Design icon, such as magnify. Each press sends a message with the «Payload» you set.

Add a button

2. Add a button that asks first ​

Add a «btn confirm» node (ui-btn-confirm) and wire it to «start or stop». It is a button with two states: the first press sends true and the button changes to its «On-Click Label», the next sends false. Each press first asks the question in «Confirmation text», so a stray touch does not stop a line. Fill in the labels and the questions for both states.

Add a button that asks first

3. Add a drop-down list ​

Add a «dropdown» node (ui-dropdown) and wire it to «remember», which keeps the choice in the flow context, where the rule of the panel reads it. Choose the group, write the «Label», «Minimum confidence», and add one option per choice, each with the value it sends and the label the operator sees: 0.5 as «50 %», 0.7 as «70 %», 0.9 as «90 %». Untick «Allow Search» so that only those can be chosen.

Add a drop-down list

4. Deploy and open the panel ​

Click «Done» and «Deploy», and open «Panels». The group «Controls» shows the three widgets, in the order they were added; drag them in the «Dashboard 2.0» tab of the editor's sidebar to change it.

Deploy and open the panel

5. Try the button ​

Press «Inspect one pack». The button sends its message to «one pack», which brings a pack; the model finds the biscuits and the canvas shows the result.

Try the button

6. Start the line, with confirmation ​

Press «Start the line». The question appears; «CONFIRM» sends true and the stream starts, «CANCEL» does nothing. The button now reads «Stop the line», and asks again before stopping.

Start the line, with confirmation

Good to know ​

  • An on and off switch. ui-btn-switch is a switch with a label for each state, such as «Inactive» and «Active». It sends true or false at once, and can ask for a password first: for a reject gate or a bypass.
  • Setting widgets from the flow. A message sent to a widget changes it: msg.payload = { status: true } puts the confirmation button in its second state, msg.enabled = false greys it out, and a value sent to the drop-down list selects it. That keeps the panel in step when the flow starts or stops by itself.
  • Who pressed. Each message from a widget carries msg._client, the browser it came from, and the signed-in user when the panel asks operators to sign in.
  • Options from the flow. msg.ui_update.options replaces the options of the drop-down list, for example with the models of the controller.

Next steps ​

Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.