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

feature request: create new rows interactively #52

Closed
Casyfill opened this issue Dec 19, 2021 · 3 comments
Closed

feature request: create new rows interactively #52

Casyfill opened this issue Dec 19, 2021 · 3 comments
Labels
question Further information is requested

Comments

@Casyfill
Copy link

Casyfill commented Dec 19, 2021

wish/feature request: it would be awesome to be able to add rows to the data frame, treating it as some kind of form

@Casyfill Casyfill changed the title feature request: create new rows interactivelt feature request: create new rows interactively Dec 19, 2021
@PablocFonseca PablocFonseca added the question Further information is requested label Jan 24, 2022
@miannini
Copy link

I'm looking forward to see this functionality in place. Would be very useful.
any way to include similar buttons on top of the table as in this link: [https://www.ag-grid.com/javascript-data-grid/data-update-transactions/](https://www.ag-grid.com/javascript-data-grid/data-update-transactions/).

@gchhablani
Copy link

I would love this feature as well! It would be pretty awesome.

@aduverger
Copy link

Hello,

With the use of Streamlit cache, you can add a button that append a row to the input dataframe of AfGrid() :

import streamlit as st
import pandas as pd
from pandas.api.types import is_bool_dtype, is_numeric_dtype
from st_aggrid import AgGrid, GridOptionsBuilder


def get_blank_from_dtype(dtype):
    """Return correct values for the new line: 0 if column is numeric, "" if column is object, ..."""
    if is_numeric_dtype(dtype):
        return 0
    elif is_bool_dtype(dtype):
        return False
    else:
        return ""

# Initialize your dataframe
if "df_for_grid" not in st.session_state:
    st.session_state.df_for_grid = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
add_row = st.button("➕ Row")
if add_row:
    st.session_state.df_for_grid = st.session_state.changed_df.append(
        pd.Series(
            [
                get_blank_from_dtype(dtype)
                for dtype in st.session_state.df_for_grid.dtypes
            ],
            index=st.session_state.df_for_grid.columns,
        ),
        ignore_index=True,
    )
gb = GridOptionsBuilder.from_dataframe(st.session_state.df_for_grid)
gb.configure_default_column(editable=True)
gridOptions = gb.build()
grid = AgGrid(
    st.session_state.df_for_grid,
    gridOptions=gridOptions,
)
st.session_state.changed_df = grid["data"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants