Skip to content

Instantly share code, notes, and snippets.

@okld
okld / components_callbacks.py
Last active March 8, 2024 22:00
Patch to use callbacks with Streamlit custom components.
"""Patch to use callbacks with Streamlit custom components.
Usage
-----
>>> import streamlit.components.v1 as components
>>> from components_callbacks import register_callback
>>>
>>> print("Script begins...")
>>>
@okld
okld / multipage_settings_app.py
Last active September 25, 2023 13:50
Streamlit - Settings page with session state
import streamlit as st
from persist import persist, load_widget_state
def main():
if "page" not in st.session_state:
# Initialize session state.
st.session_state.update({
# Default page.
"page": "home",
@okld
okld / legacy_session_state.py
Created February 19, 2022 21:36
Restore Streamlit v0.88.0 session state behavior.
"""Restore Streamlit v0.88.0 session state behavior.
The legacy session state behavior allowed widget states to be persistent,
even after their disappearance. This can be handy when making a configurable
settings page.
Usage
-----
You must call the legacy_session_state() at the beginning of your script.
@okld
okld / st_demo_rerun.py
Last active March 4, 2021 21:04
Streamlit - Periodic app rerun
import random
import streamlit as st
from streamlit.ReportThread import get_report_ctx
from streamlit.server.Server import Server
from threading import Thread
from time import sleep
def main():
st.line_chart(random.sample(range(100), 20))