Skip to content
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

Closed
eamonnmag opened this issue Oct 4, 2018 · 10 comments
Closed

selection: getting selected data #1153

eamonnmag opened this issue Oct 4, 2018 · 10 comments
Labels

Comments

@eamonnmag
Copy link

Is there a way, given a selection to give back the selected data as a dataframe for example?

@Alcampopiano
Copy link

Alcampopiano commented Oct 4, 2018

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.

sort of like this after a selection

@jakevdp
Copy link
Collaborator

jakevdp commented Oct 4, 2018

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.

@yassersouri
Copy link

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.

@jakevdp
Copy link
Collaborator

jakevdp commented Oct 14, 2019

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.

@joelostblom
Copy link
Contributor

joelostblom commented Feb 23, 2021

@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?

@Z-Shakeri
Copy link

This did the trick for me: https://stackoverflow.com/questions/64565901/how-to-retrieve-attributes-from-selected-datum-in-altair
However, you need to serve the chart in Streamlit to be able to use this solution.

@makmanalp
Copy link

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.

@jakevdp
Copy link
Collaborator

jakevdp commented Aug 27, 2021

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.

@joelostblom
Copy link
Contributor

joelostblom commented Dec 16, 2021

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

image

@jonmmease
Copy link
Contributor

This functionality will be available in Altair 5.1 using the JupyterChart jupyter widget added in #3119. This will work in all environments that support Jupyter Widgets (classic jupyter notebook, jupyter lab, colab, visual studio code, and others).

Other dashboard toolkits that want to provide this functionality will need to implement it themselves, as Panel does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants