Skip to content

Instantly share code, notes, and snippets.

View asehmi's full-sized avatar

Arvindra Sehmi asehmi

View GitHub Profile
# ISSUE: Stylistically, I prefer to have a top-level controller and then
# form "views" which get laid out on the page in the order they were called.
# With just two forms, though, callback chaining is manageable and won’t result in a tangle,
# but the layout order is inverted, and in this callbacks solution the profile report and forms
# disappear when `cluster_duplicates` is finally called.
#
# (See this thread: https://discuss.streamlit.io/t/selectbox-bug-on-chaining-forms/19927)
#
# For a better solution see: multiform_chaining.py
@asehmi
asehmi / multiform_chaining.py
Created December 14, 2021 15:18
Chaining Streamlit forms and passing values using session state API
import streamlit as st
from streamlit_pandas_profiling import st_profile_report
from streamlit import session_state as session
import numpy as np
import pandas as pd
from pandas_profiling import ProfileReport
if 'data_uploader_submitted' not in session:
session.data_uploader_submitted = False
@asehmi
asehmi / streamlit_remove_top_of_page_whitespace.py
Last active April 29, 2022 13:19
It is possible to get rid of that expanse of whitespace at the top of Streamlit apps
#
# It's a bit of a CSS hack but it is possible to get rid of that
# large amount of whitespace at the top of Streamlit apps!
#
# If this hack stops working, it's likely the Streamlit app CSS
# classes have changed. Open up dev tools and find the new names
# to update the CSS below. :-)
#
# UPDATED 29/4/2022 with new classes
#
@asehmi
asehmi / streamlit_debug.py
Last active August 7, 2024 13:13
Handy script I made to help streamline Streamlit debugging
# How to use:
#
# [1] Ensure you have `debugpy` installed:
#
# > pip install debugpy
#
# [2] In your main streamlit app:
#
# import streamlit_debug
# streamlit_debug.set(flag=True, wait_for_client=True, host='localhost', port=8765)
@asehmi
asehmi / pandas_profiler.py
Created November 29, 2021 00:50
Using pandas profiling with streamlit_pandas_profiling component in Streamlit
import streamlit as st
import pandas_profiling
from streamlit_pandas_profiling import st_profile_report
import pandas as pd
st.set_page_config(
page_title='Data Profiler',
layout='wide',
page_icon='🔍'
)
@asehmi
asehmi / multifile_uploader.py
Created November 21, 2021 22:43
Uploading and saving multiple files in Streamlit
### **data.py**
import streamlit as st
import pandas as pd
@st.experimental_memo(persist='disk')
def csv_to_df(excel_file):
df = pd.read_csv(excel_file)
return df
@asehmi
asehmi / mplfinance_streamlit_demo.py
Last active June 2, 2025 07:02
How to use mplfinance in Streamlit
from datetime import date, datetime
import streamlit as st
import pandas as pd
import mplfinance as mpf
from pandas_datareader import data as pdr
@st.experimental_memo(persist='disk')
def get_historical_data(symbol, start_date = None):
df = pdr.get_data_yahoo(symbol, start=start_date, end=datetime.now())
for col in df.columns: