altair icon indicating copy to clipboard operation
altair copied to clipboard

Deprecate `to_html()`? Or make it work with Vegafusion?

Open joelostblom opened this issue 1 year ago • 5 comments
trafficstars

What happened?

I accidentally mixed up to_html() and save and noticed that when using to_html with the vegafusion data_transformers is enabled, I run into this error:

ValueError: When the "vegafusion" data transformer is enabled, the 
to_dict() and to_json() chart methods must be called with format="vega". 
For example: 
    >>> chart.to_dict(format="vega")
    >>> chart.to_json(format="vega")
import altair as alt
import pandas as pd

alt.data_transformers.enable('vegafusion')

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
).to_html()

What would you like to happen instead?

Instead of hardcoding to_dict() without args and mode='vegalite', we could allow to pass arguments for these parameters in the to_html() method. The mode could just be named mode and the dict option could either just be format or dict_kwds similar to what we have for json_kwds. It's possible to override the mode via embed_options but I think an explicit argument would be clearer.

Another option would be to deprecate it. It has been mention in the past that it is no longer used, but not sure if it was reincarnated after that or just never removed https://github.com/altair-viz/altair/issues/420#issuecomment-376504185

Which version of Altair are you using?

main

joelostblom avatar Apr 07 '24 21:04 joelostblom