Panel won't refresh if it updates a variable that is used in another panel

Hi,

I have a custom panel plugin(“MyPanel”) that uses a custom data source, and the data source uses variables to fetch the data for the MyPanel.

The MyPanel updates variables as intended and after each variable update the MyPanel reloads and gets different data based on variables.

However, if the variable that it updates is referenced in any other panel, the variable updates(and the other panel that its referenced in) but MyPanel doesn’t reload(and because the data source uses those variables the data doesn’t change).
This happens only in case the variable is used somewhere, if its not, then MyPanel reloads properly.

Why is this happening and what would be the solution?

@igorkujacic12 If I understand correctly, your data source uses variables in the code directly, not from the Query Editor.

If it’s correct, then adding input fields, which have variables as values replaced in the code, should solve the issue. The data Source will be refreshed, and trigger panel render every time any of the mentioned variables changed.

Alternatively, you can look at the event bus event for variables updates: How to subscribe to Grafana application events

Thank you for the response, this definitively led me to a right track. My conclusion is that if variable is not being used anywhere, updating it will trigger all panels, but as soon as its used on one panel, only that one will get triggered so I have to specify that the “MyPanel”, the one managing the variable updates actually uses those variables.

After adding an input field to panel options and writing the variable there it triggers the reload after updating the variable.

Since there are more than a few variables being used, I’ve added an addSelect option to the builder and it allows me to select one variable which again works as intended. Does the addSelect option have a multi-select option? Or do I have to create a custom option?

This is the code right now(with options being extracted variables):

return builder.addSelect({
    path: "variables",
    name: 'Variables',
    description: 'Select variable to render',
    settings: {
      options: options,
      multi: true
    }
  })
1 Like

@igorkujacic12 There is an addMultiSelect.

Works perfectly! Thanks. For some reason my VS Code doesn’t recognize it even though it works, and when I was looking at suggestions for the builder it didn’t show. Anyway, it works, thanks!

1 Like

Looking forward to seeing what you built when/if you publish it.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.