Streamlit + Ibis
Ibis supports the streamlit connection
interface, making it easier than ever to combine the powers of both tools!
Check out the example application below that shows the top N ingredients from a corpus of recipes using the ClickHouse backend!
And here’s the source code for the application:
from __future__ import annotations
import requests
import streamlit as st
from ibis import _
from ibis.streamlit import IbisConnection
="Yummy Data", layout="wide")
st.set_page_config(page_title"Yummy Data :bacon:")
st.title(
@st.cache_data
def get_emoji():
= requests.get(
resp "https://raw.githubusercontent.com/omnidan/node-emoji/master/lib/emoji.json",
=60,
timeout
)
resp.raise_for_status()= resp.json()
emojis return emojis
= [1, 5, 10, 25, 50, 100]
options
@st.cache_data
def query():
return (
"snake_case")
con.tables.recipes.rename(=_.ner.map(lambda n: n.lower()).unnest())
.mutate(nermax(options))
.ner.topk(="ner")
.rename(ingredient
.to_pandas()
.assign(=lambda df: df.ingredient.map(
emojilambda emoji: f"{emojis.get(emoji, '-')}"
)
)"ingredient")
.set_index(
)
= get_emoji()
emojis
= st.connection("ch", type=IbisConnection)
con
if n := st.radio("Ingredients", options, index=1, horizontal=True):
= st.columns((2, 1))
table, whole = options.index(n)
idx = 0
k = query()
base for m in options[: idx + 1]:
= base.iloc[k:m]
df if not k:
= "first"
word elif m < n:
= "next"
word else:
= "last"
word
= " ".join(df.emoji[df.emoji != "-"].unique())
uniq_emojis f"{word.title()} {m - k:d}")
table.header(
table.subheader(uniq_emojis)
=True)
table.dataframe(df, use_container_width= m
k
= base.iloc[:n]
b = " ".join(b.emoji[b.emoji != "-"].unique())
uniq_emojis f"Top {n:d}")
whole.header(
whole.subheader(uniq_emojis)=True) whole.dataframe(b, use_container_width