# Make reusable Vega-Lite components?

**URL:** <https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [September 2, 2024, 6:53am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885 "2024-09-02T06:53:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjessing](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjessing/32/133870_2.png) [@cjessing](https://discuss.elastic.co/u/cjessing)\
**Post date:** [September 2, 2024, 6:53am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885/1 "2024-09-02T06:53:06Z")

</div>

Greetings all

As a Vega n00b I'm faced with the task of creating a dashboard with a number of boxes, each listing some data for a given server (up/down, number of containers, name etc.). Alle the data is based on metricbeat/heartbeat queries.

What I would like to accomplish is to have a generic component and to be able to enter the server id when adding the component to a dashboard. Maybe through settings when adding it?

What I'm unable to figure out is if this is possible and how to add an input variable to my Vega Lite json spec.

I'm limited to using Kibana and Vega Lite hence cannot (or don't know how) to create e.g. Elastic Javascript Client components.

If anything above makes sence I hope someone is able to point me in the right direction.

Thanks

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [September 2, 2024, 10:25am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885/2 "2024-09-02T10:25:59Z")

</div>

Hi @cjessing

is Lens not an option?  
Anyway, the solution I'm going to propose works for both Lens or Vega(-lite or not) and it's based on `Control` panels: that would help to dynamically apply a filter to the entire dashboard, as in your case the `server id`.

In the Lens panels, everything is just applied transparently.  
In Vega panels, you need to use the `%context%: true` directive in the spec as described here: [Vega | Kibana Guide [8.15] | Elastic](https://www.elastic.co/guide/en/kibana/current/vega.html#vega-queries)

---

<div class="post-metadata">

**Author:** ![cjessing](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjessing/32/133870_2.png) [@cjessing](https://discuss.elastic.co/u/cjessing)\
**Post date:** [September 2, 2024, 11:23am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885/3 "2024-09-02T11:23:10Z")

</div>

Thanks for getting back!

I think I know what the %context% parameter does but in my case, I don't need all elements to update based on a single common input parameter. I have some "must" conditions that must be met for each box (eg. hostname) and it's these condidtions that I'd like to specify for each box placed on my dashboard.

The main reason is to avoid duplicated json and to avoid generating a gigantic json file.

I'm sorry I don't know what you mean by "Control panels"?

I'll have a look at Lens again even though my colleague dismissed it at an earlier stage.

---

<div class="post-metadata">

**Author:** ![cjessing](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjessing/32/133870_2.png) [@cjessing](https://discuss.elastic.co/u/cjessing)\
**Post date:** [September 3, 2024, 6:45am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885/4 "2024-09-03T06:45:06Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/4/c/4c113e4309f8a925571470985dd8fc8986fc5c41.png)  
This is basically what I'm trying to achieve. And this is just a small piece of the entire Canvas. The Canvas we're trying to move away from. Each arrow is a query of its own and each box consists of five queries. So the Canvas page is extremely heavy to load.

We're trying to break it down and it just seems weird to have to write 9 x 7 queries to produce the content shown in the picture. It would be more elegant to create a single component to render a single box with arrows and then pass an id to the component to have it render.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [September 3, 2024, 8:29am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885/5 "2024-09-03T08:29:33Z")

</div>

It is possible to generate small multiples with Vega, as represented here: [Example Gallery | Vega-Lite](https://vega.github.io/vega-lite/examples/#faceting-trellis-plot--small-multiples)

I would suggest that route for that specific example.

---

<div class="post-metadata">

**Author:** ![cjessing](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjessing/32/133870_2.png) [@cjessing](https://discuss.elastic.co/u/cjessing)\
**Post date:** [September 3, 2024, 10:51am UTC](https://discuss.elastic.co/t/make-reusable-vega-lite-components/365885/6 "2024-09-03T10:51:51Z")

</div>

That looks interesting! Thanks!

Ah! Unfortunately [term] query does not support [repeat] 😢
