Not able to edit cell in experimental_data_editor

I am trying to have a tab under which I want to display and edit some setup parameters. However, data frame that I need to edit needs to be selectable. So I have put this in the sidebar select box. But the editor is allowing me to edit the cells of the first select box option alone. When I select a different option from the select box, it displays the new data frame, but editing is not possible. Appreciate any inputs on how to resolve this.

Code snippet:

import streamlit as st
import os
import pandas as pd
import openpyxl as xl

fname = 'Test.xlsx'

def read_xlsx2df(f, colNames):
    wb = xl.load_workbook(f)
    df_l = {}
    sh_l = []
    for sheet in wb.sheetnames:
        if sheet == 'Sheet':
            continue
        ws = wb[sheet]
        sh_l.append(sheet)
        data = ws.values
        data = list(data)
        data2 = [d for d in data if d[0] != None]
        df = pd.DataFrame.from_records(data2[1:], columns=colNames)
        df_l[sheet] = df
    return df_l

df_sheet_dict = read_xlsx2df(fname, ['Keyword', 'Value', 'Type', 'Remarks', 'Additional Notes'])

with st.sidebar:
    sel = st.selectbox(
            "Choose the setup to edit",
            df_sheet_dict.keys()
        )

t1, t2, t3 = st.tabs([f'SetupFile ({sel})', 'Status', 'Chart'])

with t1:
    ret_pd = st.experimental_data_editor(df_sheet_dict[sel])

Is there a way to attach files here. I wanted to attache the Test.xlsx file here. In any case this is how it looks:

Sheet A_1:

Keyword Value Type Remarks Additional Notes
Status Off Basic
Mode P Basic
multiplier Basic
exit_now Basic
pause Basic

Sheet B_1:

Keyword Value Type Remarks Additional Notes
Status Off Basic
Mode Q Basic
multiplier 2x Basic
exit_now True Basic
pause False Basic
time {6: β€˜14:30’, 5: β€˜14:30’, 4: β€˜14:30’, 3: β€˜14:30’, 2: β€˜14:30’, 1: β€˜14:30’, 0: β€˜14:30’} Basic
Keyword Value Type Remarks Additional Notes
Status Off Basic
Mode R Basic
multiplier Basic
exit_now Basic
pause Basic
reactivate_after_mins 2000 User

Sheet D_1:

Keyword Value Type Remarks Additional Notes
Status Off Basic
Mode S Basic
multiplier Basic
exit_now False Basic
pause Basic
reactivate_after_mins 10 User

BTW, forgot to mention the version. I am on streamlit 1.20.0 version

I think I resolved the issue after some trials. The problem was that in the Value column of my spreadsheet, some of the entries were ints/floats (essentially not str). Once I changed the entire column to str, it worked. This issue can be closed.

1 Like

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