Next button / open new page / session state

Hey @Isa ,

There is a workaround this without using session_state. It will allow you to move through your radio in the sidebar by clicking on the next button like it was explained in this solution.

To make it more clear for you I have customized the solution to respond to your request with this code:

import streamlit as st
import pickle as pkle
import os.path

pages = ['Page1','Page2','Page3']

if os.path.isfile('next.p'):
    next_clicked = pkle.load(open('next.p', 'rb'))
    if next_clicked == len(pages):
        next_clicked = 0 
else:
    next_clicked = 0 

if next:
    next_clicked = next_clicked+1
    if next_clicked == len(pages):
        next_clicked = 0 

choice = st.sidebar.radio("Pages",('Page1','Page2', 'Page3'), index=next_clicked)
pkle.dump(pages.index(choice), open('next.p', 'wb'))

if choice == 'Page1':
    st.title('Page 1')
elif choice == 'Page2':
    st.title('Page 2')
elif choice == 'Page3':
    st.title('Page 3')

next = st.button('Go to next page')

pages

Let us know if this was helpful !

1 Like