The expression widget

Learn how to use this excel-like widget to calculate what you need with scripts.

DataFromSky avatar
Written by DataFromSky
Updated over a week ago

The addition of the expression widget makes traffic data processing scriptable allowing you to treat the dashboard like an excel spreadsheet and create customized advanced traffic analytics with new functions. Your different widgets become cells that you can use as building blocks for scripts inside the expression widget. You can use the widget for a variety of use-cases such as counting the number of available parking spaces in a parking lot, measuring traffic congestion length, or balance of traffic flow.

The expression widget can be added inside the dashboard by clicking the add expression widget button which can be found on the bottom right (see the picture below). There is no limit to how many expression widgets you can create.

The expression widget looks the same as the value widget in the dashboard. You can name it and select different colors for different value ranges. Where the expression widget is different is the expression field where you write your script to calculate what you need. The script follows the rules of Javascript code.

Figure: In your script, you can use any widget value on the dashboard as an input variable.

In the expression you can use:

  • Value widgets, statistical value widgets, other expression widgets on the dashboard as input variables (you can learn about these widgets here)

  • Constant values - real or integer numbers

  • Basic mathematical operators such as +, -, /, *

  • If-else and switch statements, cycles, etc… (full JavaScript support)

  • Comparison operators <, >, ==, <=, and >=

  • Dot notation (.) for additional traffic data properties like .startDataTime(), .endDataTime() and .isValid() (these allow filtering of the data based on time and other factors)

  • Your functions with the arguments in the format: function myFunction(p1, p2) { return p1 * p2; }

All of the available variables from your dashboard will be presented as options under the Inputs section of the expression. You can simply click on the widget name to insert it into the script at your current cursor position. This automatically inserts the widget representation in the following format: $Widget ID”Widget name”. To show it on an example where the widget ID is 3 and name ”Level of service” the widget would be represented like this: $3"Level of service". For statistical value widgets, you can select which of the specific values you want to add to the script from a dropdown menu that shows up when you click on it.

The power of the expression widget is that it allows you to get the final format of the data inside of FLOW before communicating it further so there is no need for additional processing. To publish the result with the REST sink API if you select the publish as simple value REST sink option. Learn more about data sinks and how to set them up here: Introduction to data sinks and FLOW Insights' public API, Using REST sinks for traffic data retrieval. Next, we will show you an example of how the expression widget can be used.

Example: number of free parking spaces

One example of how you can use the expression widget is to calculate the number of free parking spaces. To do that you first need to add a zone, set it to live, and also add a value widget to it. Without the expression widget, you could only get the number of cars currently present in the zone. Expression widget allows you to create a script, where you input the total number of spaces in the parking lot and deduct the number of cars currently present in the zone ("Parking zone - n. currently occupied spaces"). Let's say we have a parking lot with a capacity of 18 places. The script would look like this:

18-$16"Parking zone - n. of currently occupied spaces"

We also have an example of a simple traffic congestion measuring script that can be found in this article.


You have learned how you can set up your own scripts and what elements you can use to build them. This powerful feature allows you to process the extracted traffic data in the way you need - all in real-time and based on the current traffic situation. Create your own traffic data processing workflows in just a couple of clicks and fully adapt the FLOW framework to any traffic analysis & detection task. If you need assistance with setting up your scripts please reach out to us. Let us know how you liked this guide.

Did this answer your question?