Hi, have not used Streamlit for a year or so.
Today i resumed my Streamlit journey and encountered few issues.
Issue#1 -
filter_columns = {
"PuRegion": "Region",
"PuMarket": "Market",
"PuState": "State",
"DelState": "DelState",
# "PuDay": "Day",
# "PuMonth": "Month",
}
st.sidebar.header("Choose your filter")
# Loop through all the columns
filtered_df = 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)]
This is my search bar - had to specify each of my searchable things as string format but could not do with the PuDay and PuMonth.
Had to comment out and try to find solution solution.
This is what i get:
TypeError: '<' not supported between instances of 'float' and 'str'
Traceback:
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
result = func()
^^^^^^
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 590, in code_to_exec
exec(code, module.__dict__)
File "/development/koala/1_Home.py", line 515, in <module>
choices = st.sidebar.multiselect(f"Pick your {prompt}", options=sorted(set(filtered_df[column].values)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And this is my date format:
df['PuDate'] = pd.to_datetime(df['PuDate']) # skip if your Date column already in datetime format
df['PuWeekDay'] = df['PuDate'].dt.weekday
df['PuMonth'] = df['PuDate'].dt.month # dt.month - if i have issues with groupby() method !
df['PuYear'] = df['PuDate'].dt.year
df['PuWeek'] = df['PuDate'].dt.strftime('%W') # Important to get day of the week
df['PuDay'] = df['PuDate'].dt.strftime('%A')
Looking for solution as this is a key part to me. Its filters by day ( mon, tue etc) and month ( jan, feb. etc. )
I thought it was formatted before with dt.strftime before this code is run.
Issue#2
CachedWidgetWarning: Your script uses a widget command in a cached function (function decorated with @st.cache_data or @st.cache_resource). This code will only be called when we detect a cache "miss", which can lead to unexpected results.
To fix this, move all widget commands outside the cached function.
Traceback:
File "/usr/lib/python3.12/threading.py", line 1032, in _bootstrap
self._bootstrap_inner()
File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
self.run()
File "/usr/lib/python3.12/threading.py", line 1012, in run
self._target(*self._args, **self._kwargs)
File "/development/koala/1_Home.py", line 1247, in <module>
main()
File "/development/koala/1_Home.py", line 662, in main
st_map = map_display(filtered_df)
File "/development/koala/1_Home.py", line 586, in map_display
st_map = st_folium(m, returned_objects=[], use_container_width=True)
File "/development/koala/lib/python3.12/site-packages/streamlit_folium/__init__.py", line 402, in st_folium
component_value = _component_func(
Tried this:
[client]
showErrorDetails = false
and this:
streamlit run app.py --client.showErrorDetails=false
Still showing.
Im running folium map under @st.cache_data as if my memory recalls - its faster as im running csv file with 6k rows and plenty of columns and they represents my data under folium map. plus actual app is close to 1200 lines.
Ive installed latest streamlit few days ago. Running on Linux. Python 3.12.5
Thank You!