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
def can_use_streamlit(): | |
""" | |
Function to check whether python code is run within streamlit | |
Requires Streamlit>=1.9.0 | |
Returns | |
------- | |
can_use_streamlit : boolean | |
True if code is run within streamlit, else False |
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
# Based on discussion here: https://discuss.streamlit.io/t/how-to-work-date-input-with-shortcuts/25377/3 | |
import streamlit as st | |
from datetime import datetime as dt | |
import calendar | |
state = st.session_state | |
if 'message' not in state: | |
state.message = '' |
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
# 2 range sliders | no value overlap | clamped values | |
import streamlit as st | |
state = st.session_state | |
def _set_x_cb(): | |
if state.x[1] > state.y[0]: | |
state.x = (state.x[0], state.y[0]) | |
def _set_y_cb(): | |
if state.y[0] < state.x[1]: |
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
# My solution for: https://discuss.streamlit.io/t/how-to-update-st-columns/25501/3 | |
# This uses a button callback to report the enroll action. Notice how all the widget keys are | |
# generated so they are unique. To deal with being able to edit the values from their defaults, | |
# and report on them correctly, I am printing out the widgets’ session state values. | |
import streamlit as st | |
from dataclasses import dataclass | |
state = st.session_state |
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
# My solution for: https://discuss.streamlit.io/t/how-to-update-st-columns/25501/3 | |
# This uses a button callback to report the enroll action. Notice how all the widget keys are | |
# generated so they are unique. To deal with being able to edit the values from their defaults, | |
# and report on them correctly, I am printing out the widgets’ session state values. | |
# UPDATE: Added continuous update of the students list | |
import streamlit as st | |
from dataclasses import dataclass | |
import time | |
import random |
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 itertools import cycle | |
import streamlit as st | |
num_cols = int(st.sidebar.number_input('Number columns', 1, 7, 3, 1)) | |
img_w = int(st.sidebar.number_input('Image width', 50, 500, 150, 10)) | |
images = { | |
'https://unsplash.com/photos/-YHSwy6uqvk/download?force=true&w=640': 'Feast', | |
'https://unsplash.com/photos/UC0HZdUitWY/download?force=true&w=640': 'Mixed Grill', |
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 requests | |
import streamlit as st | |
state = st.session_state | |
if 'flask_started' not in state: | |
state.flask_started = False | |
def start_flask(): | |
if state.flask_started: | |
return |
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
# | |
# This seems to be a common issue amongst new Streamlit users, so I wrote a mini-tutorial app to explain how widgets | |
# are used with initialized values and how to make them stick using session state and callbacks. | |
# | |
# There are three ways: | |
# | |
# (1) The most basic where the initial value is not given but the widget is always reset, | |
# (2) Where it’s initialized but there are issues getting the return value to stick, and finally | |
# (3) Overcoming all issues with session state and callbacks. | |
# |
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 | |
# -------------------------------------------------------------------------------- | |
def v_space(n, level=None): | |
for _ in range(n): | |
header_marks = '' | |
if level: | |
header_marks = '#' * int(level) | |
st.write(f'{header_marks} '.strip()) |
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 csv | |
import datetime as dt | |
import requests | |
import mplfinance as mpf | |
import pandas as pd | |
from pandas_datareader import data as pdr | |
import streamlit as st | |
# ----------------------------------------------------------------------------- |