Skip to content

Instantly share code, notes, and snippets.

View asehmi's full-sized avatar

Arvindra Sehmi asehmi

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / amwtmu_demo.md
Last active May 11, 2022 16:45
scraPy spaCy demo
@asehmi
asehmi / spacy-word-match-viz.py
Last active May 19, 2022 14:15
Streamlit app using spaCy's rule-based matcher to find weak phrases in requirements statements
# My solution to this: https://discuss.streamlit.io/t/the-if-else-appear-anyway/24713/7
import streamlit as st
import spacy
from spacy import displacy
from spacy.matcher import PhraseMatcher
nlp = spacy.load('en_core_web_sm') #some alternatives en_core_web_md, en_core_web_lg
nlp.disable_pipes('ner')
@asehmi
asehmi / widget_callbacks.py
Last active May 19, 2022 12:44
Setting Streamlit widget values via callbacks
# Generic answer to this question: https://discuss.streamlit.io/t/how-to-work-date-input-with-shortcuts/25377
import streamlit as st
state = st.session_state
def _set_start_cb():
if state.start > state.end:
state.start = state.end
def _set_end_cb():
if state.end < state.start: