Update a template variable from a panel

Hi,

I’m wondering if we can update template variables from a panel.

My dashboard consists of graphs that visualize internal state of network applications. The data points are filtered by several template variables

  • Host name where applications are running
  • Process ID for an application
  • Some IP addresses that’s associated with an application

The problem is that process IDs and IP addresses are not very useful when choosing an application to display, because it’s hard to see if pid 8548 or 233.0.0.123 corresponds to the application in question.

In order to make this easier, I created two tables

  1. A table pane that shows the mappings of process names and PIDs
  2. A text pane that lists known IP addresses with their descriptions

so we can easily select a PID and an IP address. But I think it’d be even better if we were able to click a row in the table to select a PID, and click an item in the list to select an IP address.

I tried something like below in the markdown. It does update the URL in the browser but doesn[t update the variable in question.

[233.0.0.123](/dashboard/db/my-dashboard?var-ipaddr=233.0.0.123)

Is there a way to do this?

1 Like

Not currently. I wrote code in a custom plugin panel that could update template variables by hacking Grafana’s internals but Grafana does not support it yet - not for users and not for plugin developers.

1 Like

Thank you. That’s a bit unfortunate. Do you know if there is a feature request for this on GitHub?

I could not find an issue for exactly this. Urls like /dashboard/db/my-dashboard?var-ipaddr=233.0.0.123 work if coming from another page but your use case is when on the same page and just changing the query string parameter?

1 Like

Yes, exactly. I’ll file a feature request then.

Hi,
I have exactly the same kind of problematic: I wish a panel to display data according to what I selected in another one. My first idea was to update a Template variable from a panel so it will affect other panels. I can only hope this will be feasible soon.
In the meantime, is there any other way(s) to make two panels communicate?

Thanks

Are both of the panels custom panels where you can change the code? You could emit an event and listen to it in another panel.

Emit: https://github.com/grafana/grafana/blob/master/public/app/core/components/grafana_app.ts#L120

Listen: https://github.com/grafana/grafana/blob/master/public/app/core/components/grafana_app.ts#L125

1 Like

Thanks for the idea, that’s indeed something I could look into.
Yet, the panel that would need to be updated is a simple graph panel, and if I can avoid re-creating/writing it to just add a listener, I’d be pleased.

It is possible to update a template variable from a panel but then you will have to dig into the internals of Grafana and recreate some of the template variable code in your panel. This is something I have done myself when building a panel but not anything I can recommend as it relies on parts of Grafana that may change in the future.

Thanks for your help. I truly don’t think I will recreate Template variable code :).
I just hope that the feature will be implemented soon.
Cheers.

hi all,
any simpler way than hacking the code to do it?

This hasn’t been priority for us in the Grafana core team and we haven’t got any PR’s for it.

For reference, this is how I did it for the Kubernetes App (the only tricky part is handling multi-value variables with the all option):

1 Like

hi
so in short this means that the trick is to modify the code in a panel so that on a given action, it update an template variable. right?

@chicco785 are you building a custom panel? This is a long thread so not sure if you mean in a custom panel or something else.

I am not building a custom panel, but I would like existing panels to allow for that, and my understanding looking at your code example is that to allow for that, you will need to change each single panel. Correct? Or is there a place in common code that would provide support for that?

Oh sorry - misunderstood your question. My reply is only valid if you are building a custom panel.

Haven’t got a PR for this yet.

This code is not working.
I am using Grafana v6.2.5 (6082d19)
using custom variable and when I change the value it updates inside the model but the current value is not changing

Got any code that you can show or share? Hard to say what the problem is and I’m not sure if the code example from 2 years ago still works.

1 Like

hi! danielee ! i am facing the same problem! i am building my custom navigation plugin with react ! i wanna implement the same func as “template variables” do, what i want is, when i click a item in my custom plugin panel, then other panels’ data would change! i am looking into AdHocFiltersCtrl.ts to find some anwsers. but i found that would be difficult to hacking into this. any advices ? thanks!!!

facing similar need here

+1