This file contains 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
# 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)) |
This file contains 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 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 |
This file contains 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
''' | |
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 |
This file contains 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 time | |
import streamlit as st | |
from streamlit.components.v1 import html | |
st.markdown('<div id="my-section-{tab_id}"></div>'.format(tab_id = "<your-tab-id>"), unsafe_allow_html=True) | |
#### Render the section as per your app | |
#### At the end, include JS that shifts attention to the section you created above |
This file contains 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 | |
from pandas.api.types import ( | |
is_categorical_dtype, | |
is_datetime64_any_dtype, | |
is_numeric_dtype, | |
is_object_dtype, | |
) | |
from datetime import datetime |