This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Hack to add per-session state to Streamlit. | |
Usage | |
----- | |
>>> import SessionState | |
>>> | |
>>> session_state = SessionState.get(user_name='', favorite_color='black') | |
>>> session_state.user_name | |
'' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --- | |
# From https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92 | |
import streamlit.ReportThread as ReportThread | |
from streamlit.server.Server import Server | |
class SessionState(object): | |
def __init__(self, **kwargs): | |
"""A new SessionState object. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import pandas as pd | |
@st.cache | |
def get_data(): | |
return pd.read_csv('https://datahub.io/core/gdp/r/gdp.csv') | |
'# World GDP' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import signal | |
import subprocess | |
import sys | |
# Parse command-line arguments. | |
if len(sys.argv) > 1: | |
folder = os.path.abspath(sys.argv[1]) | |
else: | |
folder = os.path.abspath(os.getcwd()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import os | |
import sys | |
import importlib.util | |
# Parse command-line arguments. | |
if len(sys.argv) > 1: | |
folder = os.path.abspath(sys.argv[1]) | |
else: | |
folder = os.path.abspath(os.getcwd()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit.ReportThread as ReportThread | |
from streamlit.server.Server import Server | |
def get_session_id(): | |
# Hack to get the session object from Streamlit. | |
ctx = ReportThread.get_report_ctx() | |
this_session = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit.ReportThread as ReportThread | |
from streamlit.server.Server import Server | |
class ThreadSafeSt(): | |
def __init__(self): | |
"""Object that write to a Streamlit app outside the main thread. | |
This object must be created from the main thread, and then passed | |
around to other threads so they can write to the Streamlit app. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import traceback | |
class opt_echo: | |
"""Replacement for st.echo that includes a checkbox saying "show code". | |
Usage | |
----- | |
>>> with opt_echo(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(() => { | |
/* Autohide header */ | |
const header = document.querySelector('.nH.w-asV.aiw'); | |
hide = () => { | |
header.style.transition = 'opacity 300ms 300ms, transform 300ms 300ms'; | |
header.style.opacity = 0; | |
header.style.transform = 'translateY(-50px)'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(() => { | |
const css = document.createElement('style'); | |
css.innerText = ` | |
/* Change background */ | |
.js-project-header { | |
background: #23527b!important; | |
} | |
.project-columns { | |
background: #23527b!important; |
OlderNewer