Skip to content

Instantly share code, notes, and snippets.

View treuille's full-sized avatar

Adrien Treuille treuille

View GitHub Profile
@treuille
treuille / image_paginator.py
Created October 2, 2019 19:44
Answer: Applying paginator to images
import streamlit as st
import itertools
def paginator(label, items, items_per_page=10, on_sidebar=True):
"""Lets the user paginate a set of items.
Parameters
----------
label : str
The label to display over the pagination widget.
@treuille
treuille / image_paginator.py
Created October 2, 2019 19:44
Answer: Applying paginator to images
import streamlit as st
import itertools
def paginator(label, items, items_per_page=10, on_sidebar=True):
"""Lets the user paginate a set of items.
Parameters
----------
label : str
The label to display over the pagination widget.
@treuille
treuille / pagination.py
Created October 2, 2019 19:05
Answer: A simple paginator in Streamlit
import streamlit as st
import numpy as np
def paginator(label, items, items_per_page=10, on_sidebar=True):
"""Lets the user paginate a set of items.
Parameters
----------
label : str
The label to display over the pagination widget.
@treuille
treuille / answer_100000_rows.py
Created October 2, 2019 17:05
Answer: Rendering a DataFrame with 100,000 rows
import streamlit as st
import pandas as pd
DATA_BUCKET = "http://s3-us-west-2.amazonaws.com/streamlit-demo-data/"
DATA_URL = DATA_BUCKET + "uber-raw-data-sep14.csv.gz"
read_and_cache_csv = st.cache(pd.read_csv)
data = read_and_cache_csv(DATA_URL, nrows=100000)
st.write('Data', data)
@treuille
treuille / cache_example.py
Created September 30, 2019 18:52
This demonstrates the st.cache function
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])
@treuille
treuille / caching_DAG_example.py
Last active May 30, 2023 17:18
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
@st.cache
def load_metadata():
DATA_URL = "https://streamlit-self-driving.s3-us-west-2.amazonaws.com/labels.csv.gz"
return pd.read_csv(DATA_URL, nrows=1000)
@st.cache
def create_summary(metadata, summary_type):
@treuille
treuille / pave_bug.py
Created September 25, 2019 00:03
Trying to reproduce Pavel's bug...
import streamlit as st
import pandas as pd
with st.echo():
@st.cache(ignore_hash=True)
def load_cached():
csv = pd.read_csv("http://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", nrows=100000)
return csv
df = load_cached()
@treuille
treuille / deck_gl_example.py
Last active September 23, 2019 23:54
DeckGL Example
# -*- coding: utf-8 -*-
# Copyright 2018-2019 Streamlit Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@treuille
treuille / cache_bug.py
Last active September 22, 2019 17:18
Show that there's a bug with implicit arguments when running Streamlit remotely.
import streamlit as st
x = st.slider('x', 0, 10)
y = st.slider('y', 0, 10)
@st.cache
def add_to_y(x):
return y + x
st.show(add_to_y(x))
@treuille
treuille / confirm_button_hack.py
Last active August 25, 2023 14:38
Hack to implement a confirm_button in Streamlit v0.35
"""
THIS HAS BEEN DEPRECATED!
We propose you use st.form() instead:
https://blog.streamlit.io/introducing-submit-button-and-forms/
"""
import streamlit as st
import collections