altair
altair copied to clipboard
public facing method to update a dataset in place
As was shown by @jonmmease mease in this comment: https://github.com/altair-viz/altair/pull/3281#issuecomment-1904911865 it is possible to update a full dataset in place within the alt.JupyterChart class. Currently this is possible using a primitive function jchart._py_to_js_updates().
What would an intuitive public facing method look like?
My current feeling is to do it similar to the jchart.params.
So if you do jchart.data you would get an overview of the available datasets within the specification.
The names of the datasets are also registered as attributes of jchart.data and using this method we also could assign the dataset as such:
jchart.data.data_a0e7a86c692327a18bbeb2464725124c = df_update.to_dict("records")
(currently there is a dash instead of an underscore in the dataset name)
The current default behavior of altair is to try to collect all datasets globally within datasets, so a default scope of [] should be fine in almost all occasions I think.
Other ideas are welcome too!
Edit: or jchart.datasets instead of jchart.data
I agree that having a public method for this would be convenient and I like your suggestion. I think it would be preferred over something like jchart.update_data('a0e7a86c692327a18bbeb2464725124c', df_update.to_dict("records") since users would likely already be using jchart.data to explore which ID to update. Are there any advantages that come to mind with having a function for updating the data instead of an assignment as in your suggestion? Maybe if one wants to do the update as part of list comprehension (although I think we can use the walrus operator for that nowadays)?
I think adding this feature would close https://github.com/altair-viz/altair/issues/435.