Rather than writing the entire app for you (which isnโt a minimal reproducible example and not fun ), we can give you pointers like the one below:
Here are two minimal examples that demonstrate the current undesired behavior, and how to fix it:
- The table is displayed at the top of the app
import streamlit as st
import pandas as pd
def show_df():
# This callback is executed before the rest of the code
# so the table is displayed before the subheader and so on
st.table(pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}))
st.subheader("This is a subheader")
with st.form("Form"):
text = st.text_input("Text input", key="text")
btn = st.form_submit_button("Submit", on_click=show_df)
- Table is shown below the form submit button
import streamlit as st
import pandas as pd
def show_df():
# Write dataframe to session state
st.session_state.df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
st.subheader("This is a subheader")
with st.form("Form"):
text = st.text_input("Text input", key="text")
btn = st.form_submit_button("Submit", on_click=show_df)
if btn:
# display dataframe from session state upon submitting the form
st.table(st.session_state.df)
You should be able to use the above concept and adapt it to your application.
[edit] If I had to guess (and this may not work since your code isnโt reproducible), this could work:
def show_df():
df_pred.drop(index=[1,2],inplace=True)
df_pred.set_index('Strain',inplace=True)
df2 = style_df(df_pred)
st.session_state.df2 = df2
with st.form("Show what you have"):
submit = st.form_submit_button(on_click=show_df)
if submit:
st.table(st.session_state.df2)