How to take input twice from the interface

I have created a very simple app which runs a sql script and creates a table in snowflake. But after creating the table I have to run another query on the created table and show that dataframe in the app. I was able to achieve upto here, now I have to create a option box using selectbox which gives the option for how many rows you want to see. After running the app and creating the table as soon as I am clinking on no of rows to show, the app is getting refreshed and dataframe is also gone. I tried using @st.cache where I am creating the dataframe using the second query but it is throwing some error related to _thread.lock

This is how the code look like-

def show_the_data(sql_query, con, no_of_rows):
cursor = con.cursor()
rows = cursor.fetchall()
columns = [column[0] for column in cursor.description]
df = pd.DataFrame(rows, columns)
return df.head(no_of_rows)

if run_tbl: #It checks if create table in snowflake button is clicked
no_of_rows = st.selectbox(‘show_entries’, option=[10, 25, 50, 100], index=1)
df = show_the_data(sql_query, con, no_of_rows)

I don’t know whether the following GitHub file is used for solving your problem or else you can get some idea .
GitHub repo link:-