Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Forked from treuille/cache_example.py
Last active October 7, 2019 19:59
Show Gist options
  • Save pythoninthegrass/b75d39158f42722a9c25871f8aa4fd20 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/b75d39158f42722a9c25871f8aa4fd20 to your computer and use it in GitHub Desktop.
This demonstrates the st.cache function
#!/usr/bin/env python3
# USAGE
"""
From @treuille:
pip install --upgrade streamlit
streamlit run https://gist.githubusercontent.com/pythoninthegrass/b75d39158f42722a9c25871f8aa4fd20/raw/2019640b6a9ff5da5ab6d5b11b3345ddc764b285/cache_example.py
"""
import streamlit as st
import pandas as pd
# Reuse this data across runs!
read_and_cache_csv = st.cache(pd.read_csv)
BUCKET = "https://streamlit-self-driving.s3-us-west-2.amazonaws.com/"
data = read_and_cache_csv(BUCKET + "labels.csv.gz", nrows=1000)
desired_label = st.selectbox('Filter to:', ['car', 'truck'])
st.write(data[data.label == desired_label])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment