Bad sortColumnIdx error with st.dataframe

Hi, I am new to streamlit. I used st.dataframe to render a table. I noticed that when I sorted by a column and then when I changed a state of a widget, I got the following error. I am using the latest version of streamlit. I was wondering if this will be fixed.

Hello again @gunabam!

Can you post a minimum working example over that creates this error?

It looks like a negative value was somehow passed to sort your dataframe and the widget that you changed (I’m assuming this widget controls how to sort the table?) has gone into the negatives.

You can usually control the minimum and maximum values of a widget with: min_value= some_number and max_value= some_number, but not knowing which widget or anything about your code its hard to say!

Happy Streamlit-ing!

Hi @Marisa_Smith
Thank you for your help. Here is the code that I am trying. I wanted to first show an empty table, which will later get updated with more data. I find that after I click Button, then sort by C2, then click the button No function, this error pops up. How would I fix this. If I don’t do the sort, this works perfectly fine. Much help appreciated on this! I added some images depicting the problem.

import streamlit as st
import pandas as pd

class Table:
    def __init__(self, header, column_options):

        # variables
        self.header = header
        self.column_options = column_options
        self.table = pd.DataFrame(columns=self.column_options)

        # functions

    def initalize_view(self):

        self.title_cell = st.subheader(self.header)
        self.column_options_cell = st.multiselect('Select columns to view',
        self.df_cell = st.dataframe(self.table)

    def update_view(self, df):

        if df.empty == False:
            self.table = df
            self.table = pd.DataFrame(columns=self.column_options)
        self.table = self.table[self.column_options_cell]

# data
sample_data = [{"C1": 1, "C2": 1, "C3": [], "C4": True},
               {"C1": 2, "C2": 2, "C3": ['1', '2'], "C4": False},
               {"C1": -3, "C2": -3, "C3": ['2'], "C4": True}]
sample_df = pd.DataFrame(sample_data)

# set widgets
header = 'sample data'
column_options = ['C1', 'C2', 'C3', 'C4']
sample_table = Table(header, column_options)
a = st.button('Button')
b = st.button('No function')

# actions
if a: