Editable dataframes are here! ✍️

I guess the style.applymap doesn’t work with the editable dataframe!!

Hi All, really great to finally see this feature!

I’m wondering if the ability to drag to reorder rows is in the pipeline? I know this is is possible with Glide Data Grid (as are many other features… :smirk:), and it would be very helpful for one particular use case I have. I use AG Grid for many applications, but being able to use the editable data grid in Streamlit natively would be more responsive in this case!

Thanks!

I’m currently investigating this issue and I hope there will be a fix in the next version (1.21).

2 Likes

We plan to add various ways that allow limiting what kind of data the user can provide. E.g. for number columns we will probably allow to define a min and/or max value. So you don’t even have to think about validation that.
But for very specific validations, you still might need to write some custom logic. It should be possible to do that with the edits from the session state,. but it probably is quite complex to do that. If I find some time I can write up an example.

They are already implemented. But we are still iterating on the API to activate different columns. But I expect that it will be released soon.

Reordering rows is something we maybe do anywhere in the future. But we don’t have it scheduled on our roadmap yet. So don’t expect it to come out anytime soon :frowning: You could create it as an enhancement request on Github and gather some support for this issue, this might help to prioritize it.

The doc page mentioned that

No need to compare the old and new dataframe to get the difference. Just use st.experimental_data_editor together with session state to access all edits, additions, and deletions.

Can anyone please explain a little bit more about how to get the changes in order to update the data in database?

That is the announcement, not the documentation. The actual documentation page on dataframes (linked in the announcement) has a section dedicated to getting the changed data, including sample code.

Just wanted to ask is there any way to access the edited dataframe, I tried adding/deleting columns and now i want to save this new dataframe but I am not able to ? is there any way?

That is the return value of experimental_data_editor().

Hi @lukasmasuch, how is it going with this one? I have seen version 1.21 changelog but didn’t see this fix mentioned. I was just wondering if it is coming along or if I should put effort into it myself or change some basic foundations of my app. Thank you for an otherwise awesome feature!

@Mianen Just for posterity, if anyone wants a different workaround right now, you can use experimental rerun and a flag in session state to rebuild the data editor automatically. In effect, automate that second load so the user doesn’t see or “feel” it.

import streamlit as st
import pandas as pd

if 'df' not in st.session_state:
    st.session_state.df = pd.DataFrame({'A':[1,2,3,4],'B':[1,2,3,4]})
    st.session_state.rerun = False

def rerun():
    st.session_state.rerun = True

st.session_state.df = st.experimental_data_editor(st.session_state.df, on_change=rerun)

if st.session_state.rerun:
    st.session_state.rerun = False
    st.experimental_rerun()
2 Likes

Good afternoon

Tell me, please, is there such a possibility that after adding a new row, the default values in all cells are not “None”, but 0?

Thank you in advance for your response!

That’s not inherently available at this time. You would have to manipulate the data on the backend and push it as a new baseline for the data editor.

You will have one problem though that new rows don’t actually show up right away: you have to edit some value somewhere in the dataframe for any pending new rows to push through. (That could be entering some data within a new row, or editing something on a different row.) If you add a bunch of rows and keep escaping out without entering/editing any data, then you will only see the new rows on the front end and they won’t be returned by a widget yet.

Hi all

I am trying to create an editable dataframe where one column is categorical and therefore offers choices as a dropdown once clicked. Additionally, and this is my current problem, I am trying to offer the user to input his own free text in the same column if no choice of the dropdown fits.

Once I convert the column to categorical the text input function does not work anymore.

Any ideas, if this can be accomplished?

Thanks in advance! :slight_smile:

I don’t think there is a way under the current version. They have added column controls coming out in Version 1.23 but I believe you will have the same restriction, effectively.

You could provide a separate input widget for a user to add to the list of categories, in effect using an external source to expand the options for the drop down.

1 Like

Thanks for your reply! Do you happen to know, how I can define choice options for a category column? Right now I only manage to make the choice options the unique values that are available in the column. Is there any way to define the choice options by a list without having each option present in the column?

You can specify the column type as CategoricalDtype using pandas:

1 Like

guys how to delete rows in this one ?

hey guys i’m also curios if its possible to add/delete columns in an existing data_editor just like the add/delete rows?