Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(streamlit): update to use BaseConnection interface #9550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 5 in ibis/streamlit/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/streamlit/__init__.py#L5

Added line #L5 was not covered by tests
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]):

Check warning on line 14 in ibis/streamlit/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/streamlit/__init__.py#L14

Added line #L14 was not covered by tests
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 @@

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