Dash is a web framework for building interactive data applications. It provides a callback-based programming model that is designed for scaling to heavy load with simple infrastructure.
In this guide, you’ll learn how to build Dash apps with querychat to enable rich data exploration experiences where data views update based on natural language filters.
After initializing QueryChat, use .ui() to place the chat interface in your layout, then call .init_app(app) to register querychat’s callbacks. As users interact with the chat, the store at .store_id updates automatically. Use Input(qc.store_id, "data") in your callbacks, then access values with .df(state), .sql(state), and .title(state).
Method
Description
.ui()
Returns the chat UI component
.init_app(app)
Registers querychat’s internal callbacks on your Dash app
.store_id
ID of the dcc.Store component holding query state
.df(state)
Current filtered/sorted DataFrame
.sql(state)
Current SQL query (str | None)
.title(state)
Short description of current filter (str | None)
Basic layout
The most common pattern places chat alongside your custom filtered views:
dash-custom.py
import dash_ag_grid as dagimport dash_bootstrap_components as dbcfrom querychat.dash import QueryChatfrom querychat.data import titanicfrom querychat.types import AppStateDictfrom dash import Dash, Input, Output, htmlqc = QueryChat(titanic(), "titanic")app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])app.layout = dbc.Container( [ dbc.Row( [# Left column: Chat dbc.Col(qc.ui(), width=4),# Right column: Data display dbc.Col( [ html.H3(id="data-title"), dag.AgGrid(id="data-table", className="ag-theme-balham", defaultColDef={"filter": True, "sortable": True}, dashGridOptions={"pagination": True,"paginationPageSize": 10, }, columnSize="responsiveSizeToFit", ), html.Pre(id="sql-display"), ], width=8, ), ] ) ], fluid=True,)# Register querychat's internal callbacksqc.init_app(app)# Add your own callbacks using qc.store_id@app.callback( [ Output("data-title", "children"), Output("data-table", "rowData"), Output("data-table", "columnDefs"), Output("sql-display", "children"), ], Input(qc.store_id, "data"),)def update_display(state: AppStateDict): df = qc.df(state).to_pandas() sql = qc.sql(state) orf"SELECT * FROM {qc.data_source.table_name}" title = qc.title(state) or"All Data" columns = [{"field": c} for c in df.columns]return title, df.to_dict("records"), columns, sqlif__name__=="__main__": app.run(debug=True)
Data views
The real power of querychat comes from connecting it to visualizations. Here’s an example showing both filtered data and charts:
To explore multiple datasets, use separate QueryChat instances (i.e., separate chat interfaces).
Multiple tables in one chat?
In some cases, you might be able to “pre-join” datasets into a single table and use one QueryChat instance to explore them together. In the future, we may support multiple filtered tables in one chat interface, but this is not currently available. Please upvote the relevant issue if this is a feature you’d like to see!