Multi page app in streamlit based on condition

app = MultiApp()

session_state = SessionState.get(result = False)
# Add all your application here
if session_state.result:
    app.add_app("Home", home.app)
    app.add_app("Prediction UI", data.app)
    app.add_app("Train Models", model.app)
    app.add_app("Get Data", getData.app)
    app.add_app("List Models",listModels.app)
    app.add_app("Dynamic UI for Training",dynamicUiForTraining.app)
    app.add_app("Dynamic UI for Predictions",dynamicUiPredictions.app)
    app.add_app("Explain Models UI", explain_models.app)
    # The main app
    app.run()
else:
    #st.write("Please Login/Sign up first")
    session_state.result = app.add_app("Security", security.app)
    app.run()

Hi, i am trying to add security layer to may streamlit mulitpage web app and if was thinking is above approch possible? is this possible to return value from add.add_app and based on that value decide what to show

Hi @aqib,

Welcome to the st.party!

You could clone my simple authlib, announced here, then do this:

import streamlit as st
from authlib.auth import auth, authenticated

# Adds a login expander control to top of page
user = auth(sidebar=True, show_msgs=True)

st.title('Test App')

if authenticated():
    app = MultiApp()
    app.add_app("Home", home.app)
    app.add_app("Prediction UI", data.app)
    app.add_app("Train Models", model.app)
    app.add_app("Get Data", getData.app)
    app.add_app("List Models",listModels.app)
    app.add_app("Dynamic UI for Training",dynamicUiForTraining.app)
    app.add_app("Dynamic UI for Predictions",dynamicUiPredictions.app)
    app.add_app("Explain Models UI", explain_models.app)
    # The main app
    app.run()
else:
    st.warning("Please login above to access the application.")

HTH,
Arvindra

2 Likes

Or you could look at the secure login example for the Hydralit library.

.