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)
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!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.