Programming with LLMs in R and Python
posit::conf(2026)
2026-09-14
querychat turns a question about your data into a SQL query, runs the query, and shows the result.
The built-in app includes chat, a data table, and a SQL view.
26_querychatTry to reach a conclusion from your earlier Posit Assistant conversation.
Ex: Which neighborhood has the most private rooms?
Open the data drawer and select Show Query to inspect the SQL.
Restart the app with data_dict included.
Among private rooms, which property types are most common?
Hints: data_dict is already in the file — uncomment it and restart the app.
library(shiny)
library(bslib)
library(ellmer)
library(querychat)
mtcars_qc <- QueryChat$new(mtcars, client = chat_posit())
ui <- page_sidebar(
sidebar = mtcars_qc$sidebar(),
# plots, tables, etc.
)
server <- function(input, output, session) {
mtcars_qc_vals <- mtcars_qc$server()
output$table <- renderTable({
mtcars_qc_vals$df()
})
}
shinyApp(ui, server)import polars as pl
import querychat
from chatlas import ChatPosit
from shiny import App, render, ui
mtcars = pl.read_csv("data/mtcars.csv")
mtcars_qc = querychat.QueryChat(mtcars, "mtcars", client=ChatPosit())
app_ui = ui.page_sidebar(
mtcars_qc.sidebar(),
# plots, tables, etc.
)
def server(input, output, session):
mtcars_qc_vals = mtcars_qc.server()
@render.data_frame
def data_table():
return mtcars_qc_vals.df()
app = App(app_ui, server)👨💻 _demos/27_querychat

For an app other people can use, create one client per session.
06_word-gamesI’ve set up the basic Shiny app snippet and a system prompt.
Your job: create a chatbot that plays a “20 questions” style word guessing game with you.
The model was given a secret word, and it’s your job to guess it.
Hints: Use page_chat(), chat_posit(), and chat_server()
page_chat() is a new addition! You can also use chat_ui().
page_chat() gives a conversation its own page.
It includes conversation history, a chat home, and room for artifacts and other application UI.
page_chat()A greeting explains the app and can offer prompts they can use or edit.
24_shinychat-1Open the Blockbuster renewal assistant.
Add a greeting with three suggestion cards for common renewal tasks.
Use a suggestion to draft letters for the top three lapsed members.
Hints: chat_greeting() is wired up — write the greeting with <span class="suggestion"> cards.
Give the renewal agent a clear purpose before anyone typed?
Offer prompts that match the jobs the agent can do?
Keep the agent tools and skills out of the app code you edited?
Preserve the conversation after you followed a suggestion?
A drawer — chat_drawer() — can hold the drafts an agent creates.
The user selects a letter, edits it, and saves it to the workspace.
When the agent writes or edits a letter, it calls show_letter().
show_letter() uses updateSelectInput() to select the file, then opens the drawer for review.
25_shinychat-2Complete show_letter() so it selects a draft and opens the letter drawer.
Ask the agent to draft a renewal letter for Elaine Wu.
Edit the letter in the drawer, save it, then ask the agent to revise that draft.
Hints: Use updateSelectInput() (or ui.update_select()) and chat_drawer_show()
List the drafts before it created a new version?
Write a draft named elaine-wu-v1.md or the next available version?
Open the letter it wrote in the drawer?
Preserve your edit when you saved it?
Read the current letter before it tried to edit it?