Skip to content

Instantly share code, notes, and snippets.

def get_all_cookies():
'''
WARNING: We use unsupported features of Streamlit
However, this is quite fast and works well with
the latest version of Streamlit (1.27)
RETURNS:
Returns the cookies as a dictionary of kv pairs
'''
from streamlit.web.server.websocket_headers import _get_websocket_headers
# https://github.com/streamlit/streamlit/pull/5457
'''
Getting selectbox working in streamlit can be tricky.
1)
Sometimes, when we select an option, streamlit suddenly changes (in a quick flash) to the old option.
This can be unnerving at times.
This is because when streamlit re-renders your script after the option selection, the "widget key" in session state
is already populated with the value of new option.
So you need to pass that option's index while creating the selectbox.
2)
In a multi-page streamlit app, streamlit forgets the selected option when the user navigates away from a page
import plotly
import plotly.graph_objects as go
def plotly_display_number(n, what_is_n, color='Black'):
'''
Use this display big numbers in plotly
Automatically recognizes Thousands/million/Billion and displays with a suitable prefix
'''
if n > 1e9:
n /= 1e9
@skannan-maf
skannan-maf / tagged_basket_iterator.py
Created November 17, 2021 11:37
Tagged basket iterator for Doc2vec
# Basket iterator class
class tagged_basket_iterator:
def __init__(self, tb):
self._df = tb._df
self._index = 0
def __next__(self):
total_len = len(self._df)
if self._index >= total_len:
#print("Raising after {}".format(total_len))