vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.22k stars 784 forks source link

ENH: create IPython magic to use Altair from the console #879

Open jakevdp opened 6 years ago

jakevdp commented 6 years ago

Currently the only way to use Altair from an IPython console involves manually calling chart.serve() each time you'd like to display a chart.

With a little work, we could define %altair magic that would work similarly to the %matplotlib magic, and essentially create a persistent web server that will serve charts in the background, and update them each time a new chart is created.

@ellisonbg gave the following leads on how we might approach this:

Looks like the older APIs for doing this have been deprecated in favor of new prompt_toolkit based APIs:

https://ipython.readthedocs.io/en/stable/config/eventloops.html

Here is the code in prompt_toolkit:

https://github.com/jonathanslenders/python-prompt-toolkit/tree/2.0/prompt_toolkit/eventloop

Looks like they already have code for asyncio. And a bit of docs on that:

http://python-prompt-toolkit.readthedocs.io/en/stable/pages/building_prompts.html#prompt-in-an-asyncio-application

I am guessing it wouldn't be too bad to hook up an asynchio/tornado web server for that and get it hooked up to ipython/prompt_toolkit.

CC/ @matthew-brett

matthew-brett commented 6 years ago

Nice - thanks - and thanks Brian for the suggestions.