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

Add cell selection functionality to st.dataframe #6781

Open
xareelee opened this issue Jun 2, 2023 · 9 comments
Open

Add cell selection functionality to st.dataframe #6781

xareelee opened this issue Jun 2, 2023 · 9 comments
Labels
area:events feature:st.dataframe type:enhancement Requests for feature enhancements or new features

Comments

@xareelee
Copy link

xareelee commented Jun 2, 2023

Problem

In the official tutorial about st.dataframe, it provides a well interactive UI, but it lacks one important feature: indicate the selected (row, column).

For example:

import streamlit as st
import pandas as pd
import numpy as np

df = pd.DataFrame(
   np.random.randn(50, 20),
   columns=('col %d' % i for i in range(20)))

st.dataframe(df)

We can change the last line to the following:

row, column = st.dataframe(df)

And we can select a specific cell in the GUI:

Screenshot 2023-06-02 at 21 17 16

Now we can do something with the selected row and/or column (in the above case: row==4 and column=="col 2"). For example, we can show the detail info for the selected row.


Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

@xareelee xareelee added the type:enhancement Requests for feature enhancements or new features label Jun 2, 2023
@LukasMasuch
Copy link
Collaborator

@xareelee Thanks for the suggestion! We are planning to add row selection to st.dataframe (related issue) soon. Would that already solve your use case, or do you specifically want to select a single cell in the dataframe?

@LukasMasuch LukasMasuch changed the title Feature request: make st.dataframe return selected (row, column) Add cell selection functionality to st.dataframe Jun 2, 2023
@xareelee
Copy link
Author

xareelee commented Jun 2, 2023

@LukasMasuch Yes, in most instances, returning the selected row would be useful.

@robingie
Copy link

robingie commented Jun 5, 2023

That's a great start which also could help me with my use case. Currently, I want to reduce the dependency on the custom component for AgGrid because it's not actively maintained anymore. The missing piece for me would be selecting 1-n (multi-select + checkboxes) to implement all natively with st.data_editor / st.dataframe.

@LukasMasuch
Copy link
Collaborator

btw. you can find a workaround for adding row selection in this comment: #688 (comment)

@MrChadMWood
Copy link

Bump.

I need to know metadata about the selected cell. The (row, column) combination represents a database entity in my case. Lets say (teacher, student) and the intersect is the numeric grade for that student in that teachers class.

I want to know which cell is selected so that I can redirect to another page with more info on the (teacher, student). I need to know the teacher id and student id, which can be looked up via the row and column values.

Alternatively, if there was a way to embed metadata in each cell that isn't seen by the user but can be referenced by me after a cell is selected... That could work too; I'd only need to embed the required metadata in each cell (saving the lookup step).

@kanalive
Copy link

kanalive commented Apr 4, 2024

Bump.

Was looking for this feature. This is very much needed.

@lakshminarayanareddybn
Copy link

Having cell based event callbacks help in building interactive dashboards.

@chrispy-snps
Copy link

We are also quite interested in st.dataframe row selection.

@Dev-iL
Copy link

Dev-iL commented Jun 10, 2024

I managed to create a workaround in case anybody's interested. The code for this, as well as some earlier attempts, is available in the gist. Demo:
working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:events feature:st.dataframe type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

8 participants