Individual category dropdown for each row of data editor

Hey everyone,

I am using the streamlit data editor to show data.

Is it possible to have a dropdown view with values, that are individual for every row and column of the data editor?

As far as I know, it’s only possible to set categories for each column. That means that clicking a cell shows the same categories of the respective column for all rows. In my use case I need any sort of depiction that enables individual categories for each row and column. The individual categories don’t need to be selectable, I need them for visualization only.

To illustrate my question I’ve added a short example. The use case would be to show all habitats of an animal if it can live in multiple habitats, but these habitats are individual for each animal.

import streamlit as st
import pandas as pd

df = pd.DataFrame(
    {
        "Animal": ["Lion", "Elephant", "Giraffe", "Monkey", "Zebra"],
        "Habitat": ["Savanna", "Forest", "Savanna", "Forest", "Savanna"],
    }
)

df_ed = st.data_editor(df, hide_index=True)

Thanks in advance!

(This is my first post in this forum, so feel free to tell me what I’m doing wrong.)

As you mentioned, the data editor does not support selectbox configuration at the row level. The categorical type (options) are set for the whole column and are the same for every cell in that column.

If you do not need something selectable, you can display lists within cells of the data editor (which will be uneditable).

import streamlit as st
import pandas as pd

df = pd.DataFrame(
    {
        "Animal": ["Lion", "Elephant", "Giraffe", "Monkey", "Zebra"],
        "Habitat": [["Savanna", "Forest"],["Savanna"], ["Savanna"], ["Savanna","Forest"], ["Savanna"]]
    }
)

st.dataframe(df)

image

If you basically just want a filter for your dataframe, you can use selectboxes outside of the dataframe and use the information to filter your data.

Otherwise, I may be missing what you are intending to accomplish.

Thank you very much for your reply! I think you got the problem right. I’m currently depicting data as a list (as you mentioned). That works fine so far, but for a larger amount of elements it’s not really practical. Therefore I’ll probably think of a way to depict that data outside of the data editor.

@mathcatsand
I have one more question concerning this topic. Is it possible to detect which row of the data editor is clicked (in order to show data belonging to that row in a separate table)?
I read that callback functions with click events are not supported yet. I also read about a work around with checkboxes and about the third party module “aggrid”. Do you know a way to achieve this behavior without checkboxes/aggrid? Thank you!

What you’ve listed covers your options. Using some other solution or including a column of checkboxes to manually retrieve row selections.

Selections on dataframes are on the roadmap for early 2024.