How to build a dashboard with Retool

In this tutorial you will learn how to build an agriculture dashboard using Retool.
Retool enables you to quickly build and deploy internal apps for your team. Connect to your databases and APIs, assemble UIs with drag-and-drop building blocks like tables and forms, and write queries to interact with data using SQL and JavaScript.
The following steps explain, how to build an agriculture dashboard on retool with IoT data from your akenza environment.

1. Preparing the retool layout

As a first step, log in to your retool environment, create a new app and give a name to it.
As a next step, drag a Text Component into the Header view.
Drag Components -> Commonly used -> Text into the Header.
Drag a Tabbed Container Component into the Main view and resize it to full width.
If you want to copy the example layout, you can follow the next paragraph. Alternatively, you can of course make your own layout.
Inside the tabs of the tabbed container, you need the following components:
  • The first tab (By default called “View 1”) should contain five containers.
    • Two Containers should have a Chart and a Text.
    • One Container should have two Text and one Progress Circle Component.
    • One Container should have two Text and one Progress Bar Component.
    • The last Container should have three Text Components.
  • The second tab should contain only a Mapbox Map.
  • The third tab should contain one Key Value, one Text, and one Image Component.
Click the Text Component in the Header view. The Inspector Tab will open up on the right side of your screen. To modify the behavior of a component, modify its respective variables in the inspector tab. The Value of the text for example is set to "👋 Hello {{ currentuser.firstName || 'friend' }}!". This is similar to the templating syntax of Akenza. Change firstName to lastName in the value template and see the change in your text component live. Using this knowledge play around with the components you added until you are satisfied with their variables.

2. Connecting a device

In order to connect a device on akenza, follow these steps in the chapter Connect a Device.
If you do not have a device, or yours isn’t added to the device type library, you can check out the device simulator.

3. Using the Akenza API in Retool

To access the Akenza API, an API Key is needed. To generate an API Key, check out our documentation.
Once the API Key is created, switch to the retool project. After checking the API documentation, we can see that a “get device by id” request would give us access to the static fields of the device. In order to make a request type, make sure the bottom panel is visible (the button for this is on the center top of your screen). Select New -> Resource Query. Give your new request a name like “getDevice”. Set the request type to Get and fill in the URL: https://api.akenza.io/v3/devices/{{akenzaDeviceId}} Make sure to replace the variable with the actual device Id value. You can find this value in the asset overview of your device. Set a header called x-api-key to the api key you copied earlier. Select Save and Run. You should get back a Query ran successfully with the JSON-response.
Oh look, there is the custom field data we set earlier! Don't forget to fill in your own device id and api key.
The response contains an array called customFields which has an entry that contains a key-value pair called “GPS_COORDINATES” with our data.
Collapse the bottom panel and click the mapbox map we added earlier. In the inspect mode you can see that the map is awaiting a latitude and longitude value. These values describe where the map is pointed at. Let’s point it at the Akenza Headquarters in Zurich. Enter 47.414 for the latitude and 8.533. Let’s point it at the device’s location. You can use variables to access the data we received from the API by accessing the request name. For example to get the latitude to enter this: {{ getDevice.data.customFields[0].GPS_COORDINATES.latitude }} You can figure the longitude out yourself.
In order to see where exactly the device is with a flag inside of the map, you can do this by setting the Points value to {{[{ lat: getDevice.data.customFields[0].GPS_COORDINATES.latitude, long: getDevice.data.customFields[0].GPS_COORDINATES.longitude },]}}
Now you can use the same principle to fill data into your other components.


Use the “transformer” inside of requests to go from this chaos: {{[{ lat: getDevice.data.customFields[0].GPS_COORDINATES.latitude, long: getDevice.data.customFields[0].GPS_COORDINATES.longitude },]}} to a little more orderly: {{[{ lat: getDevice.data.lat, long: getDevice.data.long },]}}
Dashboard built with Retool