Filter affecting another page

So I try to make multiple-page app where every page has a filter using pandas dataframe query. But every time I try to filter data from page 1, it effecting whole other page.

Code from page 1

import pandas as pd 
import plotly.express as px
import streamlit as st 

st.set_page_config(page_title="Data Sekolah di Kalimantan Selatan", page_icon=":bar_chart:", layout="wide", initial_sidebar_state="collapsed", menu_items=None)

hide_st_style = """
    <style>
    #MainMenu {visibility: hidden;}
    footer {visibility: hidden;}
    header {visibility: hidden;}
    </style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)

@st.cache()
def load_data():
    return pd.read_excel('data.xlsx')

df_dashboard = load_data()

st.sidebar.header("Filter Data:")
kota1 = st.sidebar.multiselect("Pilih Kota:", 
options=df_dashboard["nama_kab_kota"].unique(),  
default=df_dashboard["nama_kab_kota"].unique())

pendidikan = st.sidebar.multiselect("Pilih Pendidikan:", 
options=df_dashboard["pendidikan_sederajat"].unique(), 
default=df_dashboard["pendidikan_sederajat"].unique() )

df_dashboard_selection = df_dashboard.query(
    "nama_kab_kota == @kota1 & pendidikan_sederajat == @pendidikan"
)

df_dashboard_count = df_dashboard_selection.groupby(['nama_kab_kota', "pendidikan_sederajat"])['pendidikan_sederajat'].count()

st.title("Data Pendidikan Sederajat di Kalimantan Selatan")
st.markdown("##")

total_sekolah = int(df_dashboard["nama_sekolah"].count())
akses_internet = df_dashboard.query("dapodik_akses_internet == 'Ada'").count()
belajar_id = df_dashboard.query("sudah_memiliki_belajar_id == 'Sudah'").count()
activasi_belajar = df_dashboard.query("sudah_aktivasi_belajar_id == 'Sudah'").count()
login_rapor = df_dashboard.query("sudah_login_rapor_pendidikan == 'Sudah'").count()
explor_rapor = df_dashboard.query("sudah_eksplorasi_rapor_pendidikan == 'Sudah'").count()
download_laporan = df_dashboard.query("sudah_download_laporan == 'Sudah'").count()

col1, col2, col3 = st.columns(3)
col1.metric("Memiliki Akses Internet", str(belajar_id[0])+"/"+str(df_dashboard["dapodik_akses_internet"].count()))
col2.metric("Memiliki Belajar ID", str(belajar_id[0])+"/"+str(df_dashboard["sudah_memiliki_belajar_id"].count()))
col3.metric("Aktivasi Belajar ID", str(activasi_belajar[0])+"/"+str(df_dashboard["sudah_aktivasi_belajar_id"].count()))
col1.metric("Sudah Login Rapor", str(login_rapor[0])+"/"+str(df_dashboard["sudah_login_rapor_pendidikan"].count()))
col2.metric("Sudah Explorasi Rapor", str(explor_rapor[0])+"/"+str(df_dashboard["sudah_eksplorasi_rapor_pendidikan"].count()))
col3.metric("Sudah Download Laporan", str(download_laporan[0])+"/"+str(df_dashboard["sudah_download_laporan"].count()))

df_dashboard_pendidikan_sederajat = df_dashboard_selection.groupby(['nama_kab_kota', 'pendidikan_sederajat']).size()
new_df_dashboard_pendidikan_sederajat = df_dashboard_pendidikan_sederajat.to_frame(name = 'jumlah').reset_index()

grafik_df_dashboard_pendidikan_sederajat = px.histogram(
    new_df_dashboard_pendidikan_sederajat, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='pendidikan_sederajat', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "pendidikan_sederajat": "Sekolah"
    }      
)

grafik_df_dashboard_pendidikan_sederajat.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

df_dashboard_akses_internet = df_dashboard_selection.groupby(['nama_kab_kota', 'dapodik_akses_internet']).size()
new_df_dashboard_akses_internet = df_dashboard_akses_internet.to_frame(name = 'jumlah').reset_index()

grafik_akses_internet = px.histogram(
    new_df_dashboard_akses_internet, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='dapodik_akses_internet', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "dapodik_akses_internet": "Akses"
    },                 
)

grafik_akses_internet.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

df_dashboard_sudah_memiliki_belajar_id = df_dashboard_selection.groupby(['nama_kab_kota', 'sudah_memiliki_belajar_id']).size()
new_df_dashboard_sudah_memiliki_belajar_id = df_dashboard_sudah_memiliki_belajar_id.to_frame(name = 'jumlah').reset_index()

grafik_sudah_memiliki_belajar_id = px.histogram(
    new_df_dashboard_sudah_memiliki_belajar_id, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='sudah_memiliki_belajar_id', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "sudah_memiliki_belajar_id": "Status"
    },                 
)

grafik_sudah_memiliki_belajar_id.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

df_dashboard_sudah_aktivasi_belajar_id = df_dashboard_selection.groupby(['nama_kab_kota', 'sudah_aktivasi_belajar_id']).size()
new_df_dashboard_sudah_aktivasi_belajar_id = df_dashboard_sudah_aktivasi_belajar_id.to_frame(name = 'jumlah').reset_index()

grafik_sudah_aktivasi_belajar_id = px.histogram(
    new_df_dashboard_sudah_aktivasi_belajar_id, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='sudah_aktivasi_belajar_id', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "sudah_aktivasi_belajar_id": "Status"
    },                 
)

grafik_sudah_aktivasi_belajar_id.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

df_dashboard_sudah_login_rapor_pendidikan = df_dashboard_selection.groupby(['nama_kab_kota', 'sudah_login_rapor_pendidikan']).size()
new_df_dashboard_sudah_login_rapor_pendidikan = df_dashboard_sudah_login_rapor_pendidikan.to_frame(name = 'jumlah').reset_index()

grafik_sudah_login_rapor_pendidikan = px.histogram(
    new_df_dashboard_sudah_login_rapor_pendidikan, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='sudah_login_rapor_pendidikan', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "sudah_login_rapor_pendidikan": "Status"
    },                 
)

grafik_sudah_login_rapor_pendidikan.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

grafik_sudah_aktivasi_belajar_id.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

df_dashboard_sudah_eksplorasi_rapor_pendidikan = df_dashboard_selection.groupby(['nama_kab_kota', 'sudah_eksplorasi_rapor_pendidikan']).size()
new_sudah_eksplorasi_rapor_pendidikan = df_dashboard_sudah_eksplorasi_rapor_pendidikan.to_frame(name = 'jumlah').reset_index()

grafik_sudah_eksplorasi_rapor_pendidikan = px.histogram(
    new_sudah_eksplorasi_rapor_pendidikan, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='sudah_eksplorasi_rapor_pendidikan', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "sudah_eksplorasi_rapor_pendidikan": "Status"
    },                 
)

grafik_sudah_eksplorasi_rapor_pendidikan.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

df_dashboard_sudah_download_laporan = df_dashboard_selection.groupby(['nama_kab_kota', 'sudah_download_laporan']).size()
new_sudah_download_laporan = df_dashboard_sudah_download_laporan.to_frame(name = 'jumlah').reset_index()

grafik_sudah_download_laporan = px.histogram(
    new_sudah_download_laporan, 
    x="nama_kab_kota", 
    y="jumlah", 
    color='sudah_download_laporan', 
    barmode='group',
    height=400,
    labels={
        "nama_kab_kota": "Kota",
        "jumlah": "Jumlah",
        "sudah_download_laporan": "Status"
    },                 
)

grafik_sudah_download_laporan.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

# LAYOUT

col1, col2 = st.columns(2)
with col1:
    st.subheader("Data Jumlah Sekolah di Kalimantan Selatan")
    st.plotly_chart(grafik_df_dashboard_pendidikan_sederajat)
with col2:
    st.subheader("Data DAPODIK Akses Internet di Kalimantan Selatan")
    st.plotly_chart(grafik_akses_internet)
    
with col1:
    st.subheader("Data Sekolah yang Memiliki Belajar ID di Kalimantan Selatan")
    st.plotly_chart(grafik_sudah_memiliki_belajar_id)
with col2:
    st.subheader("Data Sekolah yang Telah Aktivasi Belajar ID di Kalimantan Selatan")
    st.plotly_chart(grafik_sudah_aktivasi_belajar_id)
    
with col1:
    st.subheader("Data Sekolah yang Sudah Login Rapor Pendidikan di Kalimantan Selatan")
    st.plotly_chart(grafik_sudah_login_rapor_pendidikan)
with col2:
    st.subheader("Data Sekolah yang Telah Eksplorasi Rapor di Kalimantan Selatan")
    st.plotly_chart(grafik_sudah_eksplorasi_rapor_pendidikan)
    
col1, col2, col3 = st.columns(3)

with col2:
    st.subheader("Data Sekolah yang Telah Mendownload Laporan di Kalimantan Selatan")
    st.plotly_chart(grafik_sudah_download_laporan)

Code from page 2

import pandas as pd 
import plotly.express as px
import streamlit as st 
from streamlit_autorefresh import st_autorefresh

# _______________________________________________ HIDDEN
st.set_page_config(page_title="Data Sekolah di Kalimantan Selatan", page_icon=":bar_chart:", layout="wide", initial_sidebar_state="collapsed", menu_items=None)

hide_st_style = """
    <style>
    #MainMenu {visibility: hidden;}
    footer {visibility: hidden;}
    header {visibility: hidden;}
    </style>
"""

st.markdown(hide_st_style, unsafe_allow_html=True)

# _______________________________________________
# @st.cache()
# def load_data():
#     return pd.read_excel('data.xlsx')

df_sekolah = pd.read_excel('data.xlsx')

df_sekolah['npsn'] = df_sekolah['npsn'].astype("string")

st.title("Data Pendidikan Sederajat di Kalimantan Selatan")
st.markdown("##")

kota = st.multiselect("Pilih Kota:", 
options=df_sekolah["nama_kab_kota"].unique(),
default=df_sekolah["nama_kab_kota"].unique() )

col1, col2 = st.columns(2)

with col1:
    st.subheader("Data Jumlah Sekolah di Kalimantan Selatan")

with col2:
    pendidikan = st.multiselect("Pilih Pendidikan:", 
    options=df_sekolah["pendidikan_sederajat"].unique(),
    default=df_sekolah["pendidikan_sederajat"].unique() )

df_sekolah_selection = df_sekolah.query(
    "nama_kab_kota == @kota & pendidikan_sederajat == @pendidikan"
)

df_sekolah_pendidikan_sederajat = df_sekolah_selection.groupby(['nama_kab_kota', 'pendidikan_sederajat']).size()
new_df_sekolah_pendidikan_sederajat = df_sekolah_pendidikan_sederajat.to_frame(name = 'jumlah').reset_index()

grafik_df_sekolah_pendidikan_sederajat = px.pie(
    new_df_sekolah_pendidikan_sederajat, 
    values="jumlah",
    names="pendidikan_sederajat"
)

grafik_df_sekolah_pendidikan_sederajat.update_layout(
    plot_bgcolor="rgba(0,0,0,0)",
    xaxis=(dict(showgrid=False))
)

col1, col2 = st.columns(2)

with col1:
    st.plotly_chart(grafik_df_sekolah_pendidikan_sederajat)
    
with col2:
    st.dataframe(df_sekolah_selection)

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