I'd like an app with a data grid that let's me upload files and modify values in cells
Drop files here
or click to upload
import streamlit as st
import pandas as pd
from st_aggrid import AgGrid, GridOptionsBuilder
st.title("Editable Data Grid")
# File uploader
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
if uploaded_file is not None:
# Read the CSV file
df = pd.read_csv(uploaded_file)
# Build grid options
gb = GridOptionsBuilder.from_dataframe(df)
# Make all columns editable
gb.configure_default_column(editable=True)
# Add selection
gb.configure_selection('multiple', use_checkbox=True)
# Build the grid options
grid_options = gb.build()
st.write("You can edit the cells directly. The grid will show the modified data.")
# Display the grid
grid_response = AgGrid(
df,
grid_options,
update_mode='MODEL_CHANGED',
allow_unsafe_jscode=True,
theme='streamlit'
)
# Get the modified data
modified_df = grid_response['data']
# Add a download button for the modified data
if st.button('Download Modified Data'):
csv = modified_df.to_csv(index=False)
st.download_button(
label="Download CSV",
data=csv,
file_name="modified_data.csv",
mime="text/csv"
)
else:
st.write("Please upload a CSV file to begin editing.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?