St.form getting displayed before st.title

Rather than writing the entire app for you (which isnโ€™t a minimal reproducible example and not fun :wink:), 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:

  1. The table is displayed at the top of the app :-1:
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)

  1. Table is shown below the form submit button :+1:
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. :balloon:

[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)
1 Like