I am trying to do a multiple page app and each page works fine independently, but when I combine them and use the page.app() trick I am having collision with data between them. They both use similar components, and the state isn’t resetting when switching pages. I have tried importing caching and doing a manual clear but that doesn’t seem to work.
Unfortunately I don’t have an answer but I’, very interested to learn about the page.app() command, Have not found this one in the documentation. Where can I find more about how it works? Hope you get your answer from someone else .
The page.app() is just an idiom, where you create multiple files with an app() method and the radio checkbox menu chooses which to call. The problem I am running into is the data for the components is colliding between the app() functions causing corruption.
Here’s the simplest top level for a multi-page app (I use all the time). You will of course need to implement app1.py
and app2.py
yourself. If app1.main()
or app2.main()
take arguments, then add them as comma separated elements in the pages
spec, e.g. [app1.main, 'arg 1', 'arg 2']
.
import streamlit as st
import app1, app2
def main():
pages = {
'App 1': [app1.main], # APP 1
'App 2': [app2.main], # APP 2
}
choice = st.sidebar.radio('What do you want to do?', tuple(pages.keys()))
pages[choice][0](*pages[choice][1:])
if __name__ == '__main__':
main()
Hope that helps.
This is exactly what I am doing as well.
Each script has it’s own app() and I import them and do the radio button.
Great, way to go. Reply was directed more at @godot63 who asked the question. Can you elaborate on your “data collision” issue?
@Bobby I am having the same problem. Have you found a solution yet?
No
@Bobby can you post a minimal example showing the data collision. It’s not easy to infer what you mean from the information given. Sharing data can only be done if you pass state between pages from the top level, or if your pages are getting data from a shared cached function/data structure, or the pages make a call to a shared external endpoint (REST API or Database), or you’re using session state.