Programmatic redirects within multipage apps

I’m currently transitioning a script to work as a multipage app now that we have support for pages right within streamlit - hooray!

With this new model, I’d like to be able to programmatically redirect a user back away from a page that’s not ready for them yet - this could be because they haven’t authenticated, or it might be that they haven’t uploaded data etc on a previous page.

Suppose I have …

.
β”œβ”€β”€ pages
β”‚   β”œβ”€β”€ 01_uploader.py
β”‚   β”œβ”€β”€ 02_viewer.py
β”‚   └── etc
└── streamlit_app.py

… and the user visits <myurl>/viewer (they may have bookmarked this, perhaps) without having previously been to <myurl>/uploader. I can easily enough make the page display nothing, but what’s the streamlit-y way to programmatically redirect them back to <myurl> or to <myurl>/uploader without causing a complete script re-run and a loss of session state?

2 Likes

I have the same problem here. If you find the solution make a contact with me please.

I also need to do something similar and would love to know how to do this

Here is a workaround for now: https://github.com/streamlit/streamlit/issues/4832#issuecomment-1201938174. Let me know you run into issues with it. Also, according to the discussion on that issue, the streamlit devs are planning to implement programmatic redirect natively in the near future.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.