hello,
I want to implement a simple app that can read in a CSV file, display and modify it using “st.data_editor”. I would like to add a ‘Reset’ button, so that if I click on it, the data in the st.data_editor table will revert to the original data from the CSV file, rather than the modified data.
Original:
Edit:
Click function:
here is my code:
import streamlit as st
import pandas as pd
meta_ori = None
def main():
global meta_ori
meta_file = st.file_uploader("Choose a CSV file for group comparisons", type="csv")
if meta_file is not None:
# load data
meta = pd.read_csv(meta_file)
meta_ori = meta.copy()
if "meta" not in st.session_state:
st.session_state.meta = meta
# show data
st.subheader("group comparisons")
annotated = st.data_editor(st.session_state.meta, hide_index=True, use_container_width=True, disabled=["sample"])
st.button("Reset", on_click=update_value)
def update_value():
global meta_ori
print( meta_ori )
st.session_state.meta = meta_ori
if __name__ == "__main__":
main()