I have an excel file which has 2 columns. I want to display this excel to our users and allow them to validate each line in excel by having 2 checkboxes next to each line. How can i do it via Streamlit?

I have an excel file which has 2 columns. I want to display this excel to our users and allow them to validate each line in excel by having 2 checkboxes next to each line. How can i do it via Streamlit?

The exact UI can be done in a number of different ways, but here’s one way:

import streamlit as st
import pandas as pd

df = pd.read_excel("sheet.xlsx")[:10]

cols = st.columns(4)
cols[0].write(f"## {df.columns[0]}")
cols[2].write(f"## {df.columns[1]}")

for idx, row in enumerate(df.itertuples()):
    cols = st.columns(4)
    cols[0].write(row[0])
    cols[1].checkbox(f"{df.columns[0]} valid?", key=f"col1_valid_{idx}")
    cols[2].write(row[1])
    cols[3].checkbox(f"{df.columns[1]} valid?", key=f"col2_valid_{idx}")

st.divider()

st.header("Results:")

for idx, row in enumerate(df.itertuples()):
    cols = st.columns(2)
    with cols[0]:
        value = row[0]
        valid = st.session_state.get(f"col1_valid_{idx}", False)
        valid_emoji = "✅" if valid else "❌"
        cols[0].write(f"{value} {valid_emoji}")
    with cols[1]:
        value = row[1]
        valid = st.session_state.get(f"col2_valid_{idx}", False)
        valid_emoji = "✅" if valid else "❌"
        cols[1].write(f"{value} {valid_emoji}")

my csv file looks like this.
image

Now i was trying to put checkboxes in the columns D (good), column E (bad), Column F(OK). (user can check all three)

After the user check boxes i want to capture it as another dataframe and save it in a new csv.

Also i so not see the content of my CSV with your code with the code.

Also knowing that i have to capture the results of this (may be by click of a button) to another dataframe, may be there is another approach to look at this problem?

Thanks alot for your quick response though :slight_smile:

Ah, in that case, then st.data_editor is your friend!

import streamlit as st
import pandas as pd

df = pd.read_excel("sheet.xlsx")[:10]

df["a_valid"] = False
df["b_valid"] = False

edited = st.data_editor(df)

st.write(edited)

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