Hi all.
I have a dashboard that uses a dropdown selectbox to select a page, as well as buttons in the sidebar. When using the selectbox, I can use widgets on any page with no problems.
However, when selecting a page from the buttons in the sidebar, the relevant page loads, but as soon as I try to interact with a widget on that page it automatically refreshes back to the 1st page, likely because the selectbox is still showing that as the selected option. Please see code below.
How can I set the value of the selectbox to avoid this?
# Import necessary libraries
from DashboardStreamlit import dbrd
from page2 import dbrd2
import streamlit as st
# Define the multipage class to manage the multiple apps in our program
class MultiPage:
# Framework for combining multiple streamlit applications.
def __init__(self) -> None:
# Constructor class to generate a list which will store all our applications as an instance variable.
self.pages = []
def add_page(self, title, func) -> None:
# Class Method to Add pages to the project
# Args:
# title ([str]): The title of page which we are adding to the list of apps
# func: Python function to render this page in Streamlit
self.pages.append({
"title": title,
"function": func
})
def run(self):
# Dropdown to select the page to run
mainbtn = st.sidebar.button("Main dashboard interface")
pg2btn = st.sidebar.button("Page 2")
if mainbtn == True:
page={'title': 'Main dashboard interface', 'function': dbrd}
if pg2btn==True:
page={'title': 'Page 2', 'function': dbrd2}
else:
page = st.selectbox(
'Globalstratos Analytics Navigation',
self.pages,
format_func=lambda page: page['title']
)
#print(page)
# run the selected app function
page['function']()