-
Notifications
You must be signed in to change notification settings - Fork 795
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
How to show altair charts from console programs? #3330
Comments
The latest version of altair that is supported by altair_viewer seems to be 4.2.2. |
Just print |
|
I see, hm. Good point! We are trying to integrate features from |
Cross reference #2866. I think we're going to remove the altair_viewer dependency and replace it with a solution based on vl-convert. The current behavior of altair_viewer (when it worked with version 4) is to display all charts in a kernel session in a single browser tab, where each new chart replaces the prior chart. I'm proposing that the new behavior with vl-convert be to open a new browser tab each time Let us know if you have opinions on this workflow @fhg-isi. |
a) The behavior of matplotlib is to wait for the first chart window do be closed before the next chart window is shown. I agree to you suggestion and would prefer a solution with several tabs because it allows to view several charts and easily compare them if wanted. |
Honestly, I really like the "replace privious" behaviour.. It allows to overwrite my old visualisation when new data arrived (slow measurement) with a new visualisation... with altair, it is really convenient to add a new chart next/above/below an already existing one if that is preferred. best regards, |
If you want this behavior, would saving the chart as html to a file that you have open in a browser tab and keep overwriting the same file path when you make changes to the chart be an option? Or is there something that this workflow does not capture?
I don't quite understand how this is related to showing charts from the terminal, could you elaborate a bit and explain if there is a difference in this regard if charts are opened in new tabs instead of overwriting the same tab? |
Well as the charts update frequently, I need a Webserver that pushes the changed html, or a local html page which refreshes from that location all the time... I will look into that. This probably is a good solution. Thanks for the hint! |
I tried. I did not have any luck with HTML, but json + a local webserver + some javascript did the trick. is there a file format more recomendable than json for this purpose? I think there is something for large data which renders in rust... would that be an option here? This is the HTML which needs to be served with for example "python -m http.server" which renders the "chart.json".
|
We might be able to replicate the altair-viewer behavior with panel's repl support: https://panel.holoviz.org/how_to/server/programmatic.html. With this approach we could also potentially integrate with JupyterChart to get two-way interactivity (including the ability to replace charts in place). Maybe |
The two-way interactivity via Jupyter Charts + Panel sounds like an interesting and powerful combo. Although I still see value in the "new tab" approach you suggested earlier in #2866 (comment), since this wouldn't have any external dependencies and could be baked into the altair base package. Adding panel + bokeh is a bigger change that maybe is better suited as part of the extras/optional requirements? |
Agreed. It would be neat to have a renderers style system for The new-tab approach I described above is probably the only mode that wouldn't require external dependencies. |
Using panel, achieving what I want is incredibly easy. Thanks a lot for the tip! import panel as pn
import altair as alt
from threading import Thread
_s = pn.panel((alt.Chart().mark_point().encode()))
def _t(_s):
_s.show(threaded=False)
_thread = Thread(target=_t, args=[_s])
_thread.daemon = True
_thread.start()
def liveVisualizeAltairChart(chart):
global _s
_s.object=chart |
Awesome, thanks for sharing your solution! |
@manzt Out of curiosity, have you thought about what it would take to launch an AnyWidget widget from a non-jupyter REPL in a standalone browser window? Similar to what panel does in https://panel.holoviz.org/how_to/server/programmatic.html. |
Hi @jonmmease, thanks for pinging me. In short, yes I have thought about it but just haven't had time to poke around with it. Long list of experiments I'd like to explore. In theory, you could launch a dedicated "widget view" in a browser tab and use the ipython kernel to drive updates. It's worth noting that such an extension wouldn't be specific to anywidget, but widgets in general would benefit. Akin to the |
I appreciate your thoughts @manzt! I didn't know if AnyWidget's standardization would make this any easier than the general widget case, but makes sense. |
Ah, I hadn't considered that. I think you're right actually ;) Good thought! |
@manzt the only thing I am missing with the solution I am using right now is the ability to use vegafusion, would that work with the anywidget approach? |
@franzhaas, you should be able to use JupyterChart with Panel's ipywidget support with If we come up with a future version based on anywidget, it would work the same way as the above, but without pulling in Panel's dependencies. There's nothing wrong with Panel's dependencies, it's just always better to consider whether there's an approach with less of them 😄 |
I'm closing this since Altair 5.3 now includes the functionality of Altair Viewer via the vl-convert package instead. See the docs on how to use the browser renderer to display charts via |
@joelostblom Awesome! unfortunately due to the efficiencies of the browser renderer, i can not use it in my usecase. I use altair to monitor a measurement as it is running and need the window to update when new data becomes available. Any plans to support this use case in the future? Thanks, |
In this blog post I explain a method how I was able to stream data into an Altair chart: https://mattijn.github.io/posts/2024-01-22-stream-piano-midi-to-altair/. Hope you find it useful to work out an approach for your usecase |
Yes this is exactly the feature set i am looking for. Due to the way my environment is set up, having the measurement start a browser to drive the visualisation is way less intrusive than having the jupyterlab session initiating the measurement... imagine the counting of the notes to be started by github-ci, offering a live visualisation in case someone looks, but normally no human interaction. For now i am happy with the panel solution. |
Hi @franzhaas, I think your panel solution is a good method for now. We could look into incorporating this into Altair in the future, but I'd prefer to find a solution without that many external dependencies. I'll keep thinking about it! |
Thanks for the additional info everyone. Feel free to reopen this issue if you want to continue to track the developments here or create a new issue specifically for this part. |
I tried to use altair in a python script using PyCharm.
If I run
chart.show()
I first got an error, that I need altair_viewer to show charts. After installing altair_viewer, I got an error
Reading the documentation, I saw that altair_view does not support altair 5.
I do not want users to install an extra PyCharm extension.
=> How can I use altair outside JupyterNotebooks?
Expected: Open a plot or browser window and show chart, similar to the features provided by Matplotlib or Plotly.
Actual: Shows misleading error messages.
Related:
The text was updated successfully, but these errors were encountered: