How to change a dashboard variable value from a plugin?


What is the best way for a panel plugin to update a variable? I have tried:

  this.$ 'var-'+name, value );

This updates the URL properly, and on browser refresh, the variables is set, but I would like to actively set it.

Thanks for any pointers!


I found a solution that works: the key is: this.variableSrv.variableUpdated(v, true);

  updateVarable(varname:string, path:string) {
      console.log('update variable', varname, path );
      let v = _.find(this.variableSrv.variables, check => {
        return === varname;
      if(v) {
        this.variableSrv.setOptionAsCurrent(v, {
          text: path,
          value: path,
        this.variableSrv.variableUpdated(v, true);
1 Like

How to you access variableSrv ? What class do you have to import?

Best regards?

You can just put variableSrv in the constructor and it will get wired up for you. See:

Thanks :slight_smile: work very well :slight_smile:

how about react plugins, how do we access variableSrv?