altair icon indicating copy to clipboard operation
altair copied to clipboard

Use object specific counter instead of a global counter for unnamed parameter & view names

Open lukasmasuch opened this issue 9 months ago • 7 comments

What is your suggestion?

Unnamed parameters and sub-charts are automatically named by using a global counter:

Parameter:

https://github.com/vega/altair/blob/f345cd9368ae2bbc98628e9245c93fa9fb582621/altair/vegalite/v5/api.py#L196-L201

Subcharts/Views:

https://github.com/vega/altair/blob/f345cd9368ae2bbc98628e9245c93fa9fb582621/altair/vegalite/v5/api.py#L2885-L2890

This will lead to different specs for the same charts in a multi-threaded/multi-user environment (e.g., Streamlit). In Streamlit, we rely on the spec to be stable to calculate a deterministic element identity across app reruns. Having this global counter makes the usage of Altair complicated. It would be awesome if the global counter would be replaced with a counter that's specific to the chart object -> which would make the chart spec stable independent of the global state.

Have you considered any alternative solutions?

No response

lukasmasuch avatar May 07 '24 13:05 lukasmasuch