Skip to content

Commit 6e98ff6

Browse files
committed
Merge branch 'dev' into restructure-folders
* dev: feat: genericizing data source using DataSource protocol: Supports SQLAlchemy and Pandas fix: No longer need to manually calls `session$ns()` with shinychat (#10) Remove website routine, no pkgdown site intended (#18)
2 parents 567ea4b + c6a24a7 commit 6e98ff6

File tree

11 files changed

+567
-179
lines changed

11 files changed

+567
-179
lines changed

.github/workflows/R-CMD-check.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
name: Package checks
1313

1414
jobs:
15-
website:
16-
uses: rstudio/shiny-workflows/.github/workflows/website.yaml@v1
17-
with:
18-
working-directory: ./pkg-r
15+
# website:
16+
# uses: rstudio/shiny-workflows/.github/workflows/website.yaml@v1
17+
# with:
18+
# working-directory: ./pkg-r
1919
routine:
2020
uses: rstudio/shiny-workflows/.github/workflows/routine.yaml@v1
2121
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ __pycache__/
22
animation.screenflow/
33
README_files/
44
README.html
5+
.DS_Store
6+
python-package/examples/titanic.db
57
.quarto
68

79
# Byte-compiled / optimized / DLL files

pkg-py/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def server(input, output, session):
5656
# chat["df"]() reactive.
5757
@render.data_frame
5858
def data_table():
59-
return chat["df"]()
59+
return chat.df()
6060

6161

6262
# Create Shiny app
@@ -171,8 +171,8 @@ which you can then pass via:
171171

172172
```python
173173
querychat_config = querychat.init(
174-
df=titanic,
175-
table_name="titanic",
174+
titanic,
175+
"titanic",
176176
data_description=Path("data_description.md").read_text()
177177
)
178178
```
@@ -185,8 +185,8 @@ You can add additional instructions of your own to the end of the system prompt,
185185

186186
```python
187187
querychat_config = querychat.init(
188-
df=titanic,
189-
table_name="titanic",
188+
titanic,
189+
"titanic",
190190
extra_instructions=[
191191
"You're speaking to a British audience--please use appropriate spelling conventions.",
192192
"Use lots of emojis! 😃 Emojis everywhere, 🌍 emojis forever. ♾️",
@@ -218,8 +218,8 @@ def my_chat_func(system_prompt: str) -> chatlas.Chat:
218218
my_chat_func = partial(chatlas.ChatAnthropic, model="claude-3-7-sonnet-latest")
219219

220220
querychat_config = querychat.init(
221-
df=titanic,
222-
table_name="titanic",
221+
titanic,
222+
"titanic",
223223
create_chat_callback=my_chat_func
224224
)
225225
```

pkg-py/examples/app-database.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from pathlib import Path
2+
3+
from seaborn import load_dataset
4+
from shiny import App, render, ui
5+
from sqlalchemy import create_engine
6+
7+
import querychat
8+
9+
# Load titanic data and create SQLite database
10+
db_path = Path(__file__).parent / "titanic.db"
11+
engine = create_engine("sqlite:///" + str(db_path))
12+
13+
if not db_path.exists():
14+
# For example purposes, we'll create the database if it doesn't exist. Don't
15+
# do this in your app!
16+
titanic = load_dataset("titanic")
17+
titanic.to_sql("titanic", engine, if_exists="replace", index=False)
18+
19+
greeting = (Path(__file__).parent / "greeting.md").read_text()
20+
data_desc = (Path(__file__).parent / "data_description.md").read_text()
21+
22+
# 1. Configure querychat
23+
querychat_config = querychat.init(
24+
engine,
25+
"titanic",
26+
greeting=greeting,
27+
data_description=data_desc,
28+
)
29+
30+
# Create UI
31+
app_ui = ui.page_sidebar(
32+
# 2. Place the chat component in the sidebar
33+
querychat.sidebar("chat"),
34+
# Main panel with data viewer
35+
ui.card(
36+
ui.output_data_frame("data_table"),
37+
fill=True,
38+
),
39+
title="querychat with Python (SQLite)",
40+
fillable=True,
41+
)
42+
43+
44+
# Define server logic
45+
def server(input, output, session):
46+
# 3. Initialize querychat server with the config from step 1
47+
chat = querychat.server("chat", querychat_config)
48+
49+
# 4. Display the filtered dataframe
50+
@render.data_frame
51+
def data_table():
52+
# Access filtered data via chat.df() reactive
53+
return chat["df"]()
54+
55+
56+
# Create Shiny app
57+
app = App(app_ui, server)

pkg-py/examples/app.py renamed to pkg-py/examples/app-dataframe.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
titanic = load_dataset("titanic")
99

10-
with open(Path(__file__).parent / "greeting.md", "r") as f:
11-
greeting = f.read()
12-
with open(Path(__file__).parent / "data_description.md", "r") as f:
13-
data_desc = f.read()
10+
greeting = (Path(__file__).parent / "greeting.md").read_text()
11+
data_desc = (Path(__file__).parent / "data_description.md").read_text()
1412

1513
# 1. Configure querychat
1614
querychat_config = querychat.init(
@@ -43,7 +41,7 @@ def server(input, output, session):
4341
@render.data_frame
4442
def data_table():
4543
# Access filtered data via chat.df() reactive
46-
return chat["df"]()
44+
return chat.df()
4745

4846

4947
# Create Shiny app

0 commit comments

Comments
 (0)