R Medicine 2026 Lightning Talk
Department of Quantitative Health Sciences
Cleveland Clinic
May 7, 2026
Live app is hosted on Posit Connect Cloud here.
Why did it write this?
SELECT * FROM master_dat WHERE DiagnosisCategory = 'HF' ORDER BY Excess DESC LIMIT 10
Comes from the querychat R package
Conceptual flow:
Provides a clever way to manipulate your app content through natural language while maintaining data security
1. Initialize chat object
library(querychat)
# In global.R
querychat_config <-
querychat_init(
data_source = querychat_data_source(master_dat, tbl_name = "HospitalHRRP"),
client = ellmer::chat_google_gemini,
greeting = "Ask me a question about the HRRP in Wisconsin",
data_description = readLines("data_description.md")
)2. Create chat UI
Supply thorough context about your data
querychat_init(
data_source = querychat_data_source(master_dat, tbl_name = "HospitalHRRP"),
client = ellmer::chat_google_gemini,
greeting = "Ask me a question about the HRRP in Wisconsin",
data_description = readLines("data_description.md")
)View source document here.
data_description.md
How do we make this work?
In ui.R
# Make a toggle
bslib::input_switch(
id = "chat_mode",
label = "Chat Mode"
),
# Show manual filters
conditionalPanel(
condition = "!input.chat_mode",
datamods::select_group_ui(id = "hospitals", params = ...)
),
# Show chat interface
conditionalPanel(
condition = "input.chat_mode",
querychat_ui(id = "chat")
),In server.R
# Traditional (simultaneous) filter
current_hospitals_temp <-
datamods::select_group_server(
id = "hospitals",
data = reactive(master_dat),
vars = reactive(c("FacilityName", "City", "County", "Zip"))
)
# Make the chat server
querychat <- querychat_server("chat", querychat_config)
# Select data based on toggle state
current_hospitals <- reactive({
if (input$chat_mode) {
temp_hospitals <- querychat$df()
} else {
temp_hospitals <- current_hospitals_temp()
# APPLY MANUAL FILTER LOGIC
}
temp_hospitals
})Use the querychat package to build the chat interface and server connection
data_description argument thoroughly for better chat experienceThe bslib::input_switch() function creates the toggle, and conditionalPanel() renders the set of filters displayed to the user, depending on what is selected
reactive() objects on the server side help pick the right dataset depending on the state of the toggle
Links: