Page reloads on every selection of selectbox

I’m trying to build a fairly basic app. That fetches new data periodically in a dataframe, and displays it on the dashboard.
Everytime I select something on the dashboard, the entire page reloads. How do i fix this?

import datetime as dt
import numpy as np
import streamlit as st
import as px
import pandas as pd

def streamlit_placeholder():
    st.title('some title')

    st.text("write something cool here")

    left, right = st.columns((0.5, 0.5))
    with left:
        station_selector = st.empty()
    with right:
        x = st.date_input(label='foobar', + dt.timedelta(days=-1), + dt.timedelta(days=5*365),
        value=(, + dt.timedelta(days=5*365 - 1))
        required_start, required_end= x

    placeholder = st.empty()
    return placeholder, left, station_selector, required_start, required_end

def fake_dataset():
    # Fake Data
    df = pd.DataFrame({
                    "sensor_name": columns*25,
                    "readings": np.random.randint(20, 30, size=100),
                    "reading_date": np.repeat(pd.date_range(end='8/8/2022', periods=25), 4)
    return df

def placeholder_fix(fake_data, placeholder, required_start, required_end):
    with placeholder.container():
        sensor_mask = fake_data['sensor_name'].str.contains(pat=st.session_state['station-selector'])
        date_mask = (fake_data['reading_date'] >= required_start) & (fake_data['reading_date'] <= required_end)

        data_to_plot = fake_data[sensor_mask & date_mask]

        fig = px.line(data_to_plot, x="reading_date", y="readings", color="sensor_name", title="Temperature (\u00B0C) readings")
        fig.update_traces(mode="markers+lines", hovertemplate=None)
        fig.update_layout(hovermode="x unified")

        fig['layout']['yaxis']['title']="Temperature (\u00B0C)"

        st.plotly_chart(fig, use_container_width=True)
def set_station_selector(left, station_selector, stations):
    with left:
        with station_selector.container():
            select_station = st.selectbox('station', stations, key='station-selector')

placeholder, left, station_selector, required_start, required_end= streamlit_placeholder()
options = ['1','2']
set_station_selector(left, station_selector, options)
def main():
    options = ['1','2']
    fake_data = fake_dataset()
    print ("why does it come here again!?")

    if set(options) != set(fake_data['sensor_name'].unique()):
        print ("here")
        set_station_selector(left, station_selector, fake_data['sensor_name'].unique())
        options = fake_data['sensor_name'].unique()
    placeholder_fix(fake_data, placeholder, required_start, required_end)

Hi @Rajiv_Nishtala -

What you are describing is how the Streamlit execution model works, which is to run the script top-to-bottom upon execution. You can manipulate this behavior through caching: