Skip to content

Instantly share code, notes, and snippets.

View asehmi's full-sized avatar

Arvindra Sehmi asehmi

View GitHub Profile
@asehmi
asehmi / custom-footer-hide-styles-app.py
Last active April 26, 2022 00:58
Streamlit app with no header and custom footer
@asehmi
asehmi / progress-bar.py
Created April 19, 2022 14:27
Standard Streamlit progress bar demo
import streamlit as st
import time
import numpy as np
progress_bar = st.sidebar.progress(0)
status_text = st.sidebar.empty()
last_rows = np.random.randn(1, 1)
chart = st.line_chart(last_rows)
for i in range(1, 101):
@asehmi
asehmi / st-option-menu.py
Last active August 13, 2024 04:59
streamlit_option_menu component for Streamlit
# UPDATED: 2 May 2022
import streamlit as st
# https://discuss.streamlit.io/t/streamlit-option-menu-is-a-simple-streamlit-component-that-allows-users-to-select-a-single-item-from-a-list-of-options-in-a-menu
# https://icons.getbootstrap.com/
from streamlit_option_menu import option_menu
st.set_page_config(page_title='Muti-page app example', layout='wide')
def do_upload_tasks():
@asehmi
asehmi / svg-render.py
Created April 19, 2022 13:56
Render SVG in Streamlit
import streamlit as st
import base64
import textwrap
# https://gist.github.com/treuille/8b9cbfec270f7cda44c5fc398361b3b1
def render_svg(svg):
"""Renders the given svg string."""
b64 = base64.b64encode(svg.encode('utf-8')).decode("utf-8")
html = r'<img src="data:image/svg+xml;base64,%s"/>' % b64
st.write(html, unsafe_allow_html=True)
@asehmi
asehmi / pomodoro.py
Created April 19, 2022 13:54
A simple Streamlit Pomodoro count down timer
import streamlit as st
import time
st.set_page_config(
page_title='Pomodoro',
layout='centered',
page_icon='🍅'
)
def count_down(ts):
@asehmi
asehmi / query-params.py
Created April 19, 2022 13:53
Setting and getting Streamlit query params
import streamlit as st
# callback to update query param on selectbox change
def update_params():
st.experimental_set_query_params(option=st.session_state.qp)
options = ["cat", "dog", "mouse", "bat", "duck"]
query_params = st.experimental_get_query_params()
@asehmi
asehmi / stqdm-demo.py
Last active October 14, 2024 06:38
STqdm: A tqdm-like progress bar for Streamlit
# UPDATED: 5-MAY-2023
from multiprocessing import Pool, freeze_support
from time import sleep
import streamlit as st
# https://discuss.streamlit.io/t/stqdm-a-tqdm-like-progress-bar-for-streamlit/10097
# pip install stqdm
from stqdm import stqdm
@asehmi
asehmi / df_flexi_query.py
Last active February 13, 2024 16:49
Flexible data filtering UI with declarative query builder [Streamlit, Pandas]
import streamlit as st
import pandas as pd
st.header('Flexible Data Filtering UI')
data = [
{
'name':'name1',
'nickname':'nickname1',
'date':2010,
@asehmi
asehmi / clear_container.py
Created December 14, 2021 15:39
Showing/hiding Streamlit panel containers
import streamlit as st
import numpy as np
c1, c2 = st.columns([1,1])
show_p1 = c1.checkbox('Show panel 1', True)
show_p2 = c2.checkbox('Show panel 2', True)
panel1 = c1.empty()
panel2 = c2.empty()
@asehmi
asehmi / multipage_session_state.py
Created December 14, 2021 15:30
Maintaining widget state across a multi-page Streamlit app
# Since widgets are created anew on each page their values will be initialized to their default values.
# I’ve created a separate ‘value cache’ to store values between pages.
# (Note, when a widget has a key and you initialize its value with a session state key value other than the widget’s own key value,
# Streamlit will complain. Therefore, the widgets don't have a key.)
import streamlit as st
# Instantiate the Session State Variables
if 'cache' not in st.session_state:
st.session_state.cache = {'name': '', 'age': '', 'gender': ''}