Sunday, September 7, 2025

Chat with knowledge the simple manner in R or Python

Save the next code to app.py and launch the app with shiny run app.py. I ran it contained in the Positron IDE with the Shiny extension put in; VS Code ought to work the identical:

 import chatlas import querychat as qc import pandas as pd from shiny import App, render, ui from dotenv import load_dotenv from pathlib import Path load_dotenv() video games = pd.read_feather("games_py.feather") def use_openai_models(system_prompt: str) -> chatlas.Chat:    return chatlas.ChatOpenAI(        mannequin="gpt-4.1",        system_prompt=system_prompt,    )   querychat_config = qc.init(     data_source=video games,     table_name="video games",     greeting=Path("greeting.md"),     data_description=Path("data_dictionary_py.txt"),     create_chat_callback= use_openai_models  ) # Create UI app_ui = ui.page_sidebar(     qc.sidebar("chat"),     ui.output_data_frame("data_table"), ) # Shiny server logic def server(enter, output, session):     # This create a querychat object utilizing the configuration from above     chat = qc.server("chat", querychat_config)     #    chat.df() is the filtered/sorted reactive knowledge body     @render.data_frame     def data_table():         return chat.df() # Create Shiny app app = App(app_ui, server) 

You must now have a fundamental working Shiny app that solutions questions on NFL knowledge.

There’s much more you are able to do with these packages, together with connecting to an SQL database and enhancing the Shiny software. Posit CTO Joe Cheng, the creator of querychat, demo’d an expanded Python model as a full-blown querychat dashboard app. There’s a template for it within the Shiny for Python gallery:

Screenshot of the Python sidebot for querychat.

Sharon Machlis

There’s additionally a demo repo for an R sidebot you may run domestically by cloning the R sidebot GitHub repository. Or, you may study the app.R file within the repository to get concepts for a way you would possibly create one.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles