Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't concatenate charts that are loaded from json #3788

Open
OleBialas opened this issue Feb 4, 2025 · 0 comments
Open

Can't concatenate charts that are loaded from json #3788

OleBialas opened this issue Feb 4, 2025 · 0 comments
Labels
bug needs-triage Bug report needs maintainer response

Comments

@OleBialas
Copy link

What happened?

I want to store charts as JSON, exchange them with collaborators and then concatenate them.
However, attempting to concatenate the charts loaded from JSON/dict raises the following error:

I am trying to store charts as JSON, then load and concatenate them either horizontally or vertically.
Howeve, this raises the following error:

TypeError: Objects with 'config' attribute cannot be used within HConcatChart. Consider defining the config attribute in the HConcatChart object instead.

Here is a simple example to reproduce this behavior:

import altair as alt
from vega_datasets import data

cars = data.cars()

dct = alt.Chart(cars).mark_point().encode(
    x="Horsepower",
    y="Miles_per_Gallon"
).to_dict()

alt.hconcat(alt.Chart.from_dict(dct), alt.Chart.from_dict(dct))

It seems the issue is cause by the "config", "$schema" and "datasets" field in the dictionary.
The only workaround I found was to remove those keys and then pass the data argument to the concatenation function:

ct.pop('config')
dct.pop('$schema')
dct.pop('datasets')

alt.hconcat(alt.Chart.from_dict(dct), alt.Chart.from_dict(dct), data=cars)

However, this somewhat defeats the purpose because the shared Vega JSON is not self sufficient and depends on the availability of the data.
Is this behavior of hconcat/vconcat intended? I feel like this should be possible in Vega-Altair.

Thanks for this great package!

What would you like to happen instead?

No response

Which version of Altair are you using?

5.5.0

@OleBialas OleBialas added bug needs-triage Bug report needs maintainer response labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-triage Bug report needs maintainer response
Projects
None yet
Development

No branches or pull requests

1 participant