Skip to content

Instantly share code, notes, and snippets.

View asehmi's full-sized avatar

Arvindra Sehmi asehmi

View GitHub Profile
@asehmi
asehmi / form-callback-demo.py
Created May 3, 2022 21:29
Demonstrate 3 different ways to run operations with form values in Streamlit
import streamlit as st
st.header('Experiments with forms')
st.markdown('There is no connection between the forms here. The purpose is to demonstrate 3 different ways to run operations with form values.')
state = st.session_state
if 'word_choices' not in state:
state.word_choices = []
@asehmi
asehmi / st_demo_settings.py
Created April 19, 2022 18:16
In-App settings panel for Streamlit
import streamlit as st
def main():
pages = {
"Home": page_home,
"Settings": page_settings,
}
if "page" not in st.session_state:
@asehmi
asehmi / voxels.py
Created April 19, 2022 18:10
Plotting voxels in Streamlit
"""From https://matplotlib.org/3.1.0/gallery/mplot3d/voxels.html in Streamlit"""
import matplotlib.pyplot as plt
import numpy as np
import streamlit as st
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
@st.cache
@asehmi
asehmi / asyncio-test.py
Created April 19, 2022 18:03
Using asyncio in Streamlit
import asyncio
import streamlit as st
from datetime import datetime
st.set_page_config(layout="wide")
st.markdown(
"""
<style>
.time {
@asehmi
asehmi / streamlit_runner.py
Created April 19, 2022 17:59
Multi-app runner for Streamlit
'''
Run Streamlit apps inside other apps. See: https://discuss.streamlit.io/t/multiple-apps-from-a-folder-file-list/181
'''
import streamlit as st
import os
import sys
import importlib.util
# https://gist.github.com/tvst/f13b24198e256c1c4d9b5ccbc6991cc2
@asehmi
asehmi / pydeck-layers.py
Created April 19, 2022 17:49
Streamlit pydeck layers
import streamlit as st
import pandas as pd
import pydeck as pdk
view_state = pdk.ViewState(latitude=32,
longitude=35,
zoom=7,
pitch=0)
d1 = {'lon': [35, 35.1], 'lat': [32.5, 32.6], 'name':['meA', 'meB'], 'prec':[100,300], 'temp':[10,30], 'elevationValue':[100,300]}
@asehmi
asehmi / opt-echo.py
Created April 19, 2022 17:45
Optional echo code for Streamlit
import streamlit as st
import traceback
# https://gist.github.com/tvst/6e62360a712ed0595e7a0749127fba58
class opt_echo:
"""Replacement for st.echo that includes a checkbox saying "show code".
Usage
-----
>>> with opt_echo():
... a = 1337
@asehmi
asehmi / asyncio-queue-producer-consumer.py
Created April 19, 2022 16:17
Asyncio Queue Producer-Consumer Pattern in Streamlit
# See this thread: https://discuss.streamlit.io/t/best-fastest-practice-to-display-live-2d-data/19895
# Code below is lifted from @andfanilo's comment
# https://realpython.com/async-io-python/#using-a-queue
import asyncio
from datetime import datetime
# pip install opencv-python-headless
import cv2
import numpy as np
@asehmi
asehmi / echarts-animation-demo.py
Created April 19, 2022 15:21
Streamlit echarts animation demo
import json
import random
import time
import streamlit as st
# pip install streamlit-echarts
from streamlit_echarts import st_echarts
st.title("I ❤️ ECharts")
@asehmi
asehmi / aggrid-demo.py
Created April 19, 2022 15:19
Streamlit AgGrid Demo
# https://discuss.streamlit.io/t/selection-is-sometimes-not-returned-from-custom-widgets/21202
import streamlit as st
# https://github.com/PablocFonseca/streamlit-aggrid
from st_aggrid import AgGrid, GridOptionsBuilder
import pandas as pd
import numpy as np
np.random.seed(42)