Hi, I'm have problem with mycode.When i select in or out something in filter or selected some think in selected box it return the login page

Capture

This is my code:
import streamlit as st
from streamlit_option_menu import option_menu
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
import altair as alt
from PIL import Image
from plotly.subplots import make_subplots

Set Page

st.set_page_config(
page_title=“Multipage App”,
page_icon=“:heart:”,
layout=“wide”,
)

VALID_USERNAME = “123”
VALID_PASSWORD = “123”

#Nevigative Bar
selected = option_menu(
menu_title=None,
options=[“Home”,“Annual Report”,“Risk Calculated”], #Pages
icons= [“1-square-fill”,“2-square-fill”,“3-square-fill”],
default_index=0,
orientation=“horizontal”
)

if selected == “Annual Report”:
username_placeholder = st.empty()
password_placeholder = st.empty()
username = username_placeholder.text_input(“Username”)
password = password_placeholder.text_input(“Password”, type=“password”)
login_button_placeholder = st.empty()
if login_button_placeholder.button(“Log in”):
if username == VALID_USERNAME and password == VALID_PASSWORD:
username_placeholder.empty()
password_placeholder.empty()
login_button_placeholder.empty()

        alt.themes.enable("default")

        
        st.title("Report of Annual Health Examinations")
        st.write(" : Report of annual health examinations is a Dashboard that shows details about the health examination results of employees in the company from 2561 to 2563.")


            #Data to USE
        df_61 = pd.read_excel("DataToStreamlit.xlsx", sheet_name="61")
        df_62 = pd.read_excel("DataToStreamlit.xlsx", sheet_name="62")
        df_63 = pd.read_excel("DataToStreamlit.xlsx", sheet_name="63")
        dfs = pd.concat([df_61, df_62, df_63], ignore_index=True)



            #multi selection
        st.sidebar.markdown("<h1 style='text-align: center; font-size: 20px;'>Health Examination</h1>", unsafe_allow_html=True)
        st.sidebar.image('Online Doctor-cuate (1).png')

        CompanyCode_selection = st.sidebar.multiselect(
                "**Select Company Code :**",
                options=dfs["Company_Code"].unique(),
                default=dfs["Company_Code"].unique(),
            )

        Employee_selection = st.sidebar.multiselect(
                "**Select Type Employee :**",
                options=dfs["TYPE_employee"].unique(),
                default=dfs["TYPE_employee"].unique(),
            )

        Sex_selection = st.sidebar.multiselect(
                "**Select Sex :**",
                options=dfs["Sex"].unique(),
                default=dfs["Sex"].unique(),
            )




        filter = dfs[(dfs["Company_Code"].isin(CompanyCode_selection)) &
                (dfs["TYPE_employee"].isin(Employee_selection)) &
                (dfs["Sex"].isin(Sex_selection))]



            #compute sum employee
        count_employ61 = filter[filter['Year'] == 2561]['No'].count()
        count_employ62 = filter[filter['Year'] == 2562]['No'].count()
        count_employ63 = filter[filter['Year'] == 2563]['No'].count()


        total1, total2, total3 = st.columns(3, gap="large")
        with total1:
                st.info('Total Employee : 2561')
                st.metric(label='Persons', value=f"{count_employ61:,.0f}")

        with total2:
                st.info('Total Employee : 2562')
                st.metric(label='Persons', value=f"{count_employ62:,.0f}")

        with total3:
                st.info('Total Employee : 2563')
                st.metric(label='Persons', value=f"{count_employ63:,.0f}")




        col1, col2 = st.columns([2, 1])   
        with col2:
                Year_selection = st.slider(             
                    "Select Year:",
                    min_value=min(dfs["Year"]),
                    max_value=max(dfs["Year"]),
                    value=(min(dfs["Year"]), max(dfs["Year"]))
            )
                
                filtered_data = dfs[dfs["Year"].between(*Year_selection) & (dfs["Company_Code"].isin(CompanyCode_selection))&
                                (dfs["TYPE_employee"].isin(Employee_selection)) &
                                (dfs["Sex"].isin(Sex_selection))]
            #-------Chart for each Examination
                data_examination = filtered_data[['PE','BLOODPRESSURE','PULSE','BMI','CHO','TRI','HDL','LDL','FBS','UricAcid',
                                            'สรุปการทำงานของตับ', 'ALK.PHOSPHATASE', 'สรุปทำงานไต', 'AFP', 'CEA',
                                            'ผลเลือดจากรพ.', 'สรุปผลปัสสาวะ', 'ZincinBlood', 'NickelinBlood', 'ManganeseinBlood',
                                            'LeadinBlood', 'ChromiuminUrine', 'TolueneinUrine', 'AcetoneinUrine',
                                            'n-HexaneinUrine', 'StyreneinUrine', 'ThinnerinUrine', 'XyleneinUrine',
                                            'MethanolinUrine', 'MEKinUrine', 'MuscleHand', 'MuscleLeg', 'Ear', 'Eye',
                                            'ColourBlindness', 'Spiro', 'X-RAY', 'EKG', 'EST', 'ECHO', 'US']] 
                exam_selection = st.selectbox(
                        "**Select Examination :**",
                        options=data_examination.columns)
            
                if not exam_selection:
                    st.warning("Please select at least one examination.")
                else:
            
                    examination_filter = data_examination[exam_selection]

                st.image('Doctors-cuate.png', use_column_width=True)

            
        count_exam = examination_filter[examination_filter == 1].groupby(by=filtered_data['Year']).count()


        with col1:
                st.write("   ")
                st.write("#### The Examination Health Results") 
                st.write(": The examination health results by the values ​​displayed in each section only consider employees who have passed each type of health examination.")
                exam_chart = px.bar(count_exam,
                                text=count_exam,
                                color_discrete_sequence=['#E13838'],
                                template='plotly_white')
                
                
                exam_chart.update_xaxes(title='Year', tickvals=['2561', '2562', '2563'])
                exam_chart.update_yaxes(title='Number of Abnormal Cases')

                st.plotly_chart(exam_chart, use_container_width=True)




            #compute sum employee
        count_exemploy61 = examination_filter[(filter['Year'] == 2561) & ((examination_filter == 0) | (examination_filter == 1))].count()
        count_exemploy62 = examination_filter[(filter['Year'] == 2562) & ((examination_filter == 0) | (examination_filter == 1))].count()
        count_exemploy63 = examination_filter[(filter['Year'] == 2563) & ((examination_filter == 0) | (examination_filter == 1))].count()

        total1, total2, total3 = st.columns(3, gap="large")
        with total1:
                st.info('Number of Employees : 2561')
                st.metric(label=': Undergoing Health Examinations', value=f"{count_exemploy61:,.0f}")

        with total2:
                st.info('Number of Employees : 2562')
                st.metric(label=': Undergoing Health Examinations', value=f"{count_exemploy62:,.0f}")

        with total3:
                st.info('Number of Employees : 2563')
                st.metric(label=': Undergoing Health Examinations', value=f"{count_exemploy63:,.0f}")



                    
        col1, col2, col3 = st.columns(3)

        with col1:
                
                exam_piechart61 = examination_filter[(filter['Year'] == 2561) & ((examination_filter == 0) | (examination_filter == 1))]
                exam_pie61 = px.pie(exam_piechart61,
                                    names=exam_piechart61,
                                    title='Percent of Abnormal Cases Examination : 2561',
                                    hole=0.65,
                                    color_discrete_sequence=['#E13838', '#0E4C8A'])

                st.plotly_chart(exam_pie61, use_container_width=True)

        with col2:
                
                exam_piechart62 = examination_filter[(filter['Year'] == 2562) & ((examination_filter == 0) | (examination_filter == 1))]
                exam_pie62 = px.pie(exam_piechart62,
                                    names=exam_piechart62,
                                    title='Percent of Abnormal Cases Examination : 2562',
                                    hole=0.65,
                                    color_discrete_sequence=['#E13838', '#0E4C8A'])

                st.plotly_chart(exam_pie62, use_container_width=True)

        with col3:
                
                exam_piechart63 = examination_filter[(filter['Year'] == 2563) & ((examination_filter == 0) | (examination_filter == 1))]
                exam_pie63 = px.pie(exam_piechart63,
                                    names=exam_piechart63,
                                    title='Percent of Abnormal Cases Examination : 2563',
                                    hole=0.65,
                                    color_discrete_sequence=['#E13838', '#0E4C8A'])

                st.plotly_chart(exam_pie63, use_container_width=True)




            #-----Personal Results
        st.markdown('#### Personal Health Examination Results')
        st.write(': The results of personal health examinations in the company.')

        ID_data = dfs[dfs["Year"].between(*Year_selection) & (dfs["Company_Code"].isin(CompanyCode_selection))&
                        (dfs["TYPE_employee"].isin(Employee_selection)) &
                        (dfs["Sex"].isin(Sex_selection))]

        col1, col2 = st.columns([2, 1])   
        with col1:
                try:
                    id_selection = st.selectbox(
                        "**Search ID :**",
                        options=ID_data['ID']
                    )

                    if not id_selection:
                        st.warning("Please Search ID.")
                    else:
                        
                        id_filter = ID_data.loc[ID_data['ID'] == id_selection]

                    st.write(id_filter)
                except KeyError:
                    st.warning("No data available for the selected year range.")

        with col2:
                st.write('  ')
                st.write('  ')
                st.write('  ')
                st.write('  ')
                st.write('  ')
                st.write('  ')
                st.write('  ')
                st.write('  ')
                st.write('  ')    
                st.image('Doctor-cuate.png', use_column_width=True)




            #-----NCDs
        st.markdown('#### The Risk Factors that cause NCDs')
        st.write(': The results of health examinations that are risk factors that cause chronic non-communicable diseases (NCDs).')

            #-------Chart for each NCDs Examination
        data_ncds = filtered_data[['BLOODPRESSURE', 'BMI', 'CHO', 'TRI', 'HDL', 'LDL', 'FBS']]
        ncds_selection = st.selectbox(
                    "**Select NCDs Examination :**",
                    options=data_ncds.columns)

            
        if not ncds_selection:
                st.warning("Please select at least one examination.")
        else:
            
                ncds_filter = data_ncds[ncds_selection]

            
        count_ncds = ncds_filter[ncds_filter == 1].groupby(by=filtered_data['Year']).count()




            #compute
        percent_ncds61 = (ncds_filter[(ncds_filter == 1) & (filtered_data['Year'] == 2561)].sum() / ncds_filter[filtered_data['Year'] == 2561].count()) * 100
        percent_ncds62 = (ncds_filter[(ncds_filter == 1) & (filtered_data['Year'] == 2562)].sum() / ncds_filter[filtered_data['Year'] == 2562].count()) * 100
        percent_ncds63 = (ncds_filter[(ncds_filter == 1) & (filtered_data['Year'] == 2563)].sum() / ncds_filter[filtered_data['Year'] == 2563].count()) * 100

        total1, total2, total3 = st.columns(3, gap="large")
        with total1:
                st.metric(label='Percent of Abnomal Case : 2561', value=f"{percent_ncds61:,.2f} %")

        with total2:
                st.metric(label='Percent of Abnomal Case : 2562', value=f"{percent_ncds62:,.2f} %")

        with total3:
                st.metric('Percent of Abnomal Case : 2563', value=f"{percent_ncds63:,.2f} %")



        col1, col2 = st.columns(2)   
        with col1:
            
                ncds_chart = px.bar(count_ncds, 
                                text=count_ncds,
                                color_discrete_sequence=['#E13838'],
                                template='plotly_white',
                                title = 'Number of Abnormal Case')

            
                ncds_chart.update_xaxes(title='Year', tickvals=['2561', '2562', '2563'])
            
                ncds_chart.update_yaxes(title='Number of Abnormal Cases')

                st.plotly_chart(ncds_chart, use_container_width=True)


        with col2:
                percent_ncds = ncds_filter[ncds_filter == 1].groupby(by=filtered_data['Year']).size() / ncds_filter.groupby(by=filtered_data['Year']).size() * 100

                ncdsline_chart = px.line(
                    percent_ncds,
                    title='Percentage of Abnormal Case')

                ncdsline_chart.update_xaxes(title='Year', tickvals=['2561', '2562', '2563'])
                ncdsline_chart.update_yaxes(title='Percentage of Abnormal Cases', range=[0, 100])

                st.plotly_chart(ncdsline_chart, use_container_width=True)
        st.button("Log out")
    else:
        st.error("Invalid username or password")

Hi @Fong

Could you elaborate more on the issue that you’re facing. Also can you explain the expected behavior of the app if it was to work properly.

Thanks!

I am working on a project. In this project, there will be 1 page that must be logged in to be able to view it. But when I log in and want to change information in a filter or selected box, the screen returns to the page. login

Hi @Fong

Perhaps this login example app https://app-app.streamlit.app/ from @blackary could be a great inspiration towards the app that you’re intending to build

Here’s the corresponding repo GitHub - blackary/streamlit-login