St.data_editor: auto-fill a value in added rows

Hello,

Is it possible to automatically insert a value set by code when adding a new row by using st.data_editor?
For example, created a st.data_editor with 2 lines. In the first column, there should always be an ascending number (1, 2, 3, etc.) instead of None. Is there any “nice” way to implement this?

Thanks for your help!

1 Like

There is a default parameter for all the editable column types here: st.column_config - Streamlit Docs

For example:

import pandas as pd
import streamlit as st

data_df = pd.DataFrame(
    {
        "widgets": ["st.selectbox", "st.number_input", "st.text_area", "st.button"],
    }
)

st.data_editor(
    data_df,
    column_config={
        "widgets": st.column_config.TextColumn("Widgets", default="st.")
    },
    hide_index=True,
    num_rows="dynamic",
)

This will add a st. as the default value in every new row. Unfortunately, this can only be a static value currently and not something dynamic like an ascending number.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.