-
Notifications
You must be signed in to change notification settings - Fork 782
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
selection: getting selected data #1153
Comments
I've never seen that in Altair but perhaps Jake knows a way. Something similar might be to have the selection displayed as a table (like a heat map but with text marks in the cells), but I know this is not exactly what you are asking. |
No, there's no easy way to do that at the moment. If you write a custom javascript frontend, it is theoretically possible via the vega view api, but I don't know of any example of that. Making this easier is on the Vega-Lite roadmap, and once it's developed there we can think about how to support it from the Python side. |
It would be nice to use the altair chart as a way to let user select input for some other part of code. Currently I am using streamlit and such a usecase is coming up but I cannot really do anything about it. |
Yes, it would be nice, and no, there is still no way to do this, because the selection happens in the Javascript layer and there is no mechanism for the Javascript to communicate back to Python. Enabling this would require changes to Altair, vega-embed, the vega IPython extension, and the vega Jupyter extension. I don't know of anybody working on this – if it's important to you, you might consider exploring what it would take. |
@eamonnmag It is not currently possible to emit signals from Altair/VegaLite to Ipywidgets (or any other widget framework). There is some work on this for Jupyter in https://github.com/yifanwu/b2 and for Streamlit in streamlit/streamlit#2263. There is also an open issue for supporting this in Panel holoviz/panel#2365. Since this is not an issue that Altair can solve, would you mind closing this issue and continue discussion in one of the links above or on the Vega-Lite issue tracker? |
This did the trick for me: https://stackoverflow.com/questions/64565901/how-to-retrieve-attributes-from-selected-datum-in-altair |
One reason this would be helpful is that it enables using altair charts as highly tuned selection dialog for a more complicated tool. E.g. I have various timeseries and various histogram and scatterplot views of the data within - so I can use linked brushing to very quickly visually do highly complicated subselections that'd be 5-10 lines of super annoying code and a couple of minutes to write. Here's how folks do it in bokeh right now (admittedly fairly gnarly): https://stackoverflow.com/questions/34164587/get-selected-data-contained-within-box-select-tool-in-bokeh Any workaround with somehow getting vega to debug log the selection values in the console so I can copy paste easily would go a long of the way! Might try to figure that out, and will report results back. |
Agreed this would be very nice to have. Note that the Streamlit developers have created a solution that works on their frontend. Nobody has yet stepped-up to create a more generally-usable solution. |
The capability to listen to Vega events and define custom callback for e.g. selected points was recently merged in Panel and will likely be included in their next major release, exciting! holoviz/panel#2592 and now in the docs at https://pyviz-dev.github.io/panel/reference/panes/Vega.html |
This functionality will be available in Altair 5.1 using the Other dashboard toolkits that want to provide this functionality will need to implement it themselves, as Panel does. |
Is there a way, given a selection to give back the selected data as a dataframe for example?
The text was updated successfully, but these errors were encountered: