Giter Club home page Giter Club logo

Comments (3)

aduverger avatar aduverger commented on May 19, 2024 1

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"]

from streamlit-aggrid.

miannini avatar miannini commented on May 19, 2024

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/).

from streamlit-aggrid.

gchhablani avatar gchhablani commented on May 19, 2024

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

from streamlit-aggrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.