i am using below code but when i am putting my query in st.text_area and hitting execute query then st.text_area is getting collapsed
if connection_status == "Connection successful":
# Provide a text box for the user to enter a query
query = st.text_area("Enter your SQL query:")
result_container = st.empty()
if st.button("Execute Query"):
if query:
try:
# Execute the query and capture the results
cursor = conn.cursor()
cursor.execute(query)
rows = cursor.fetchall()
column_names = [column[0] for column in cursor.description]
if not rows:
st.warning("No results found.")
else:
result_df = pd.DataFrame(rows, columns=column_names)
result_container.subheader("Query Results")
result_container.dataframe(result_df)
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file:
result_df.to_csv(temp_file.name, index=False)
result_container.markdown(
f"### [Download CSV](data:file/csv;base64,{temp_file})")
except Exception as e:
result_container.error(f"Error executing the query: {str(e)}")
else:
st.warning("Please enter a query.")