Hi, my st.slider causes my streamlit app to rerun. I tried to find out what is what and ended up with this code for testing purpose and i came to conclusion that is something wrong with st.slider. But im maybe wrong.
this is my full code.
from typing import List, Tuple
import pandas as pd
import plotly.express as px
import streamlit as st
import pickle
from pathlib import Path
import datetime as dt
from datetime import datetime
from datetime import date
from streamlit_option_menu import option_menu
import numpy as np
import folium
import branca
import branca.colormap as cm
from branca.colormap import linear
import plotly.graph_objects as go
from streamlit_folium import st_folium
import streamlit_authenticator as stauth
import warnings
import io
import time
from annotated_text import annotated_text
from streamlit_extras.dataframe_explorer import dataframe_explorer
import altair as alt
# from vega_datasets import data
st.set_page_config(page_title="Dashboard", page_icon=":bar_chart:", layout="wide")
# ---- HIDE STREAMLIT STYLE ----
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
with st.sidebar:
st.header("Configuration")
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is None:
st.info(" Upload a file through config", icon="ℹ️")
st.stop()
@st.cache_data
def load_data(path: str):
df = pd.read_csv(path, engine="pyarrow") # IMPORTANT !!! - to read DATA !!!!
df[["PuCity State", "PuZip"]] = df["PickUp"].str.rsplit(" ", n=1, expand=True) # Split to City, State and Zip for Outbound | Outbound = Pick Up & P=PU
df[["PuCity", "PuState"]] = df["PuCity State"].str.rsplit(" ", n=1, expand=True)
df[["DelCity State", "DelZip"]] = df["Delivery"].str.rsplit(" ", n=1, expand=True) # Split to City, State and Zip for Inbound | Inbound = Delivery & D=Del
df[["DelCity", "DelState"]] = df["DelCity State"].str.rsplit(" ", n=1, expand=True)
df[["PuCity State", "PuZip"]] = df["PickUp"].str.rsplit(" ", n=1, expand=True) # Split to City, State and Zip for Outbound | Outbound = Pick Up & P=PU
df[["PuCity", "PuState"]] = df["PuCity State"].str.rsplit(" ", n=1, expand=True) # State and Zip split to Stat, Zip
df[["DelCity State", "DelZip"]] = df["Delivery"].str.rsplit(" ", n=1, expand=True) # Split to City, State and Zip for Inbound | Inbound = Delivery & D=Del
df[["DelCity", "DelState"]] = df["DelCity State"].str.rsplit(" ", n=1, expand=True) # State and Zip split to Stat, Zip
df['PuDate'] = pd.to_datetime(df['PuDate'])
return df
df = load_data(uploaded_file)
#Date , Miles, Weight columns
col1, col2, col3, col4 = st.columns((4))
with col1:
startDate = pd.to_datetime(st.date_input("Start Date", pd.to_datetime(df["PuDate"]).min()))
with col2:
endDate = pd.to_datetime(st.date_input("End Date", pd.to_datetime(df["PuDate"]).max()))
with col3:
svoris = st.slider('Weight', min_value=df["Weight"].min(), max_value=df["Weight"].max(), value=[df["Weight"].min(), df["Weight"].max()])
with col4:
mylios = st.slider('Miles', min_value=df["Miles"].min(), max_value=df["Miles"].max(), value=[df["Miles"].min(), df["Miles"].max()])
filtered_df = df[(df["PuDate"] >= startDate) & (df["PuDate"] <= endDate) & (df["Weight"] >= svoris[0]) & (df["Weight"] <= svoris[1]) & (df["Miles"] >= mylios[0]) & (df["Miles"] <= mylios[1])].copy()
filter_columns = {
"PuRegion": "Region",
"PuMarket": "Market",
"PuState": "State",
}
st.sidebar.header("Choose your filter")
# Loop through all the columns
filtered_df = filtered_df.copy()
for column, prompt in filter_columns.items():
choices = st.sidebar.multiselect(f"Pick your {prompt}", options=sorted(set(filtered_df[column].values)))
if choices:
filtered_df = filtered_df[filtered_df[column].isin(choices)]
filtered_df = filtered_df.reset_index()
st.header("")
# filtered_df = st.data_editor(filtered_df, num_rows="dynamic", height=500)
st.dataframe(filtered_df)
Streamlit versions 1.27.0 / 1.27.1 / 1.27.2 / 1.28.0 behave in the same manner as i thought it might be version problem so i started to go trough version but encountering same problem.
OS. Arch Linux
Thank You.