I am new to using Streamlit and am creating an app which must have a login page and after login, it must display some query results. The results page must have a sidebar. However, the sidebar shows up now even on the login page despite the sidebar code being inside the function that renders the result page only after a condition checks True. The code is roughly as follows. What am I missing or doing wrong?
def app_title():
st.title("App Title")
st.write("App Description")
def login_page(placeholder):
with placeholder:
login = st.container()
with login:
app_title()
st.write("\n")
st.write("\n")
st.subheader("Login")
st.text_input("Username")
pwd = st.text_input("Password",type="password")
if len(pwd) > 0:
return True
return False
def results_page(placeholder):
with placeholder:
results = st.container()
with results:
app_title()
st.write("\n")
st.write("\n")
sps_list = ['XYZ', 'ABC']
selected_sps = st.sidebar.selectbox("Choose sps", sps_list)
from_date = st.sidebar.date_input('From', date.today())
to_date = st.sidebar.date_input('To', date.today())
submit = st.sidebar.button("Submit")
if submit:
st.markdown(f"\n**Results for {selected_sps}**")
res = search_for_sps(selected_sps, from_date, to_date)
metadata = fetch_metadata(res)
metadata_df = pd.DataFrame(metadata)
st.dataframe(metadata_df)
def main():
main_placeholder = st.empty()
success = login_page(main_placeholder)
if success:
main_placeholder.empty()
results_page(main_placeholder)
if __name__ == "__main__":
main()