Custom Variable with Datasource Plugin Not Displaying (Grafana v11.3.1)

Hi, I’m developing a datasource plugin for Grafana, and I need it to populate a Query-type variable. The response sent by the plugin is as follows

{
  "results": {
    "StandardVariableQuery": {
      "status": 200,
      "frames": [
        {
          "schema": {
            "name": "response",
            "refId": "StandardVariableQuery",
            "fields": [
              {
                "name": "text",
                "type": "string",
                "typeInfo": {
                  "frame": "string"
                }
              },
              {
                "name": "value",
                "typeInfo": {
                  "frame": "string"
                }
              }
            ]
          },
          "data": {
            "values": [
              [
                "Option 1",
                "Option 2"
              ],
              [
                "value1",
                "value2"
              ]
            ]
          }
        }
      ]
    }
  }
}

However, the dropdown for the variable remains empty and does not display any options.

What I’ve Checked So Far:

  1. I used the Query Inspector tool to verify that the request and response are correctly sent from the plugin.
  2. The response format appears to comply with the DataFrame documentation:
  • It contains text and value fields.
  • The values in the values array are of equal length and in the correct order.
  1. Here’s the plugin code generating this response:
func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
    res := backend.NewQueryDataResponse()

    for _, q := range req.Queries {
        frame := data.NewFrame("response",
            data.NewField("text", nil, []string{"Option 1", "Option 2"}),
            data.NewField("value", nil, []string{"value1", "value2"}),
        )
        res.Responses[q.RefID] = backend.DataResponse{
            Frames: data.Frames{frame},
        }
    }

    return res, nil
}

Questions:

  1. Does my response format have any issues that might prevent Grafana from displaying the values?
  2. Are there any specific settings I need to configure for Grafana variables to work with my plugin?
  3. Could this issue be related to the Grafana version (v11.3.1)?

Any help or suggestions to resolve this issue would be greatly appreciated. :pray:


Grafana Version: v11.3.1

Thank you in advance!

Hello,

If you are using the method metricFindQuery to add support for query variables, you shouldn’t use a DataFrame to display results but a simple object with {text: value}.

See more details of how to do it here: Add support for variables | Grafana Plugin Tools