Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This demonstrates how piping cached functions into one another automatically sets up an efficient directed acyclic computational graph.
import streamlit as st
import pandas as pd
def load_metadata():
return pd.read_csv(DATA_URL, nrows=1000)
def create_summary(metadata, summary_type):
one_hot_encoded = pd.get_dummies(metadata[["frame", "label"]], columns=["label"])
return getattr(one_hot_encoded.groupby(["frame"]), summary_type)()
# Piping one st.cache function into another forms a computation DAG.
summary_type = st.selectbox("Type of summary:", ["sum", "any"])
metadata = load_metadata()
summary = create_summary(metadata, summary_type)
st.write('## Metadata', metadata, '## Summary', summary)
Copy link

treuille commented Sep 30, 2019

You can run this gist directly from the command line with:

pip install --upgrade streamlit
streamlit run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment