Using Variables to Switch Data Displayed in the Panel

Overview

By default, a panel can display data from only one device. Creating separate panels for each device can quickly consume screen space and require significant effort. To address this, variables allow dynamic data visualization.

With Variables, you can achieve:

Dashboards with Variables cannot be shared with third parties. Avoid using Variables in dashboards intended for sharing with third parties.

This page explains features commonly used in Lagoon. For additional features, refer to the Variables documentation in Grafana.

https://g-v3.lagoon.soracom.io

Variables Settings

In Dashboard settings > Variables, you can add, duplicate, or delete variables.

There are several variable types, but in Soracom Lagoon, three types are commonly used:

Common Parameters

General

Even if you select Nothing, you can still change the Variable by adding var-{variable}={value} to the dashboard URL's query parameters.

Selection options

Query

The Query variable type lets you create a variable representing a resource ID or name using a regular expression. For example, you can create variables that include the names of all IoT SIMs owned by an operator.

You can use the key of your data in Soracom Harvest Data as a variable, but you cannot use the value of your data as a variable.

Query options

Variable values can be previewed in the Preview of values section.

Custom

With the "Custom" variable type, you can create variables with arbitrary strings.

Custom options

Preview variable values in the Preview of values section.

Text box

With the "Text box" variable type, you can input variable values directly at the top of the dashboard.

Text options

Query Settings

In the panel editor, you can configure queries to use variables. To learn more, refer to Using Query to Display Data on the Panel.

Panel Settings

In the panel editor, you can configure Soracom Lagoon to dynamically add panels to a dashboard based on variable values. Variables dynamically change queries across all panels in a dashboard. To configure repeating panels:

  1. Open the dashboard containing the panel you want to edit.
  2. Click the panel title and select Edit.
  3. In the display options pane, click Panel options > Repeat options.
  4. Select a direction:
    • Choose horizontal to arrange panels side-by-side. Soracom Lagoon adjusts the width of repeated panels. You cannot mix other panels in the same row with a repeated panel.
    • Choose vertical to arrange panels in a column. Repeated panels will have the same width as the original panel.
  5. Reload the dashboard to propagate changes to all panels.

You can also use variables in the panel title or description by setting the Title or Description fields.

If you set variables for the Resource Name in the query but do not configure the Repeat options in the panel options, you can display multiple resources within a single panel using variables. However, the number of resources that can be displayed simultaneously in a panel using variables is limited to 5.

Row Settings

Soracom Lagoon supports dynamically adding rows to a dashboard based on variable values. To configure repeating rows:

  1. Open the dashboard containing the panel you want to edit.
  2. In the Add a panel dialog box, click Add a new row.
  3. Hover over the row title and click the cog icon.
  4. In the Row Options dialog box, set a title for the row and select the variable for which you want to add repeating rows.
  5. Save your changes.

Example Usage

In this example, you will create repeated panels and rows using variables in Soracom Lagoon. The Demo sample data has the following structure:

Create a New Dashboard

  1. Log in to the Soracom Lagoon console.
  2. From the sidebar, click the Dashboard icon.
  3. Click the New dropdown button.
  4. Select New Dashboard.

Create a Query Variable for Devices

  1. In the Variables page, click New variable.
  2. Select Query as the variable type.
  3. Configure the following options:
    • Name: devices
    • Data source: Harvest
    • Query: demo
    • Regex: /Device-/
  4. Check the Multi-value option.
  5. Click Apply.

Create a Custom Variable for Metrics

  1. Navigate to Dashboard settings > Variables and click Add variable.
  2. Select Custom as the variable type.
  3. Configure the following options:
    • Name: metrics
    • Values separated by comma: temperature,humidity
  4. Check the Include All option.
  5. Click Apply.

Configure Queries Using Variables

  1. If you are on the Variables page, click "←" (Go back) or press the Esc key to return to the Dashboard editor.
  2. Click Add panel and select Add a new panel.
  3. In the Query tab, set the following:
    • For Resource Type, select Demo.
    • For Resource Name, select $devices.
    • For Property, select $metrics.

Enable Repeated Panels

  1. In the panel editor, navigate to Panel options > Repeat options.
  2. Configure the following options:
    • Title: Set to $devices $metrics.
    • Repeat by variable: Select metrics.
    • Repeat direction: Choose Horizontal.
  3. Click Apply to save the panel settings.

Create a Repeated Row for Devices

  1. Add a new row to the dashboard by clicking Add panel and selecting Add a new row.
  2. Hover over the row title and click the cog icon to open Row options.
  3. Configure the following options:
    • Title: Set to $devices.
    • Repeat for: Select devices.
  4. Click Update to apply the settings.

See the Result

After completing these steps, the dashboard will dynamically create:

You can control your dashboard by selecting values in the devices and metrics variables.

https://g-v3.lagoon.soracom.io

This setup ensures a flexible and scalable visualization of your data with minimal manual configuration.