Skip to content

Commit

Permalink
refactor(streamlit): update to use BaseConnection interface (#9550)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndexSeek authored Jul 11, 2024
1 parent 232e783 commit f5dd8fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def get_emoji():
@st.cache_data
def query():
return (
con.tables.recipes.relabel("snake_case")
con.tables.recipes.rename("snake_case")
.mutate(ner=_.ner.map(lambda n: n.lower()).unnest())
.ner.topk(max(options))
.relabel(dict(ner="ingredient"))
.rename(ingredient="ner")
.to_pandas()
.assign(
emoji=lambda df: df.ingredient.map(
Expand All @@ -43,7 +43,7 @@ def query():

emojis = get_emoji()

con = st.experimental_connection("ch", type=IbisConnection)
con = st.connection("ch", type=IbisConnection)

if n := st.radio("Ingredients", options, index=1, horizontal=True):
table, whole = st.columns((2, 1))
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/visualization/streamlit.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Streamlit + Ibis

Ibis supports the [streamlit `experimental_connection` interface](https://blog.streamlit.io/introducing-st-experimental_connection/), making it easier than ever to combine the powers of both tools!
Ibis supports the [streamlit `connection` interface](https://docs.streamlit.io/develop/concepts/connections/connecting-to-data), 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](../../backends/clickhouse.qmd)!

Expand Down
14 changes: 7 additions & 7 deletions ibis/streamlit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any

from streamlit.connections import ExperimentalBaseConnection
from streamlit.connections import BaseConnection
from streamlit.runtime.caching import cache_data

import ibis
Expand All @@ -11,14 +11,14 @@
__all__ = ["IbisConnection"]


class IbisConnection(ExperimentalBaseConnection[BaseBackend]):
class IbisConnection(BaseConnection[BaseBackend]):
def _connect(self, **kwargs: Any) -> BaseBackend:
"""Connect to the backend and return a client object.
This method is invoked when `st.experimental_connection` is called and
pulls information from streamlit secrets. `_connect` is part of the
streamlit connection API to be implemented by developers of specific
connection types.
This method is invoked when `st.connection` is called and pulls
information from streamlit secrets. `_connect` is part of the streamlit
connection API to be implemented by developers of specific connection
types.
Here's an example not-so-secret configuration:
Expand Down Expand Up @@ -48,7 +48,7 @@ def _connect(self, **kwargs: Any) -> BaseBackend:
from ibis.streamlit import IbisConnection
con = st.experimental_connection("ch", type=IbisConnection)
con = st.connection("ch", type=IbisConnection)
# Now you can use `con` as if it were an ibis backend
con.list_tables()
Expand Down

0 comments on commit f5dd8fb

Please sign in to comment.