-
Notifications
You must be signed in to change notification settings - Fork 963
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display pandas DataFrame as interactive table (#1373)
* Add Dataframe class * Add Dataframe component * Add @mui/x-data-grid package * Refactor Dataframe element to handle DataFrame serialization internally --------- Co-authored-by: Mathijs de Bruin <mathijs@mathijsfietst.nl>
- Loading branch information
1 parent
00f96b8
commit f6159d5
Showing
17 changed files
with
384 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
from chainlit.element import ( | ||
Audio, | ||
Component, | ||
Dataframe, | ||
File, | ||
Image, | ||
Pdf, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pandas as pd | ||
|
||
import chainlit as cl | ||
|
||
|
||
@cl.on_chat_start | ||
async def start(): | ||
# Create a sample DataFrame with more than 10 rows to test pagination functionality | ||
data = { | ||
"Name": [ | ||
"Alice", | ||
"David", | ||
"Charlie", | ||
"Bob", | ||
"Eva", | ||
"Grace", | ||
"Hannah", | ||
"Jack", | ||
"Frank", | ||
"Kara", | ||
"Liam", | ||
"Ivy", | ||
"Mia", | ||
"Noah", | ||
"Olivia", | ||
], | ||
"Age": [25, 40, 35, 30, 45, 55, 60, 70, 50, 75, 80, 65, 85, 90, 95], | ||
"City": [ | ||
"New York", | ||
"Houston", | ||
"Chicago", | ||
"Los Angeles", | ||
"Phoenix", | ||
"San Antonio", | ||
"San Diego", | ||
"San Jose", | ||
"Philadelphia", | ||
"Austin", | ||
"Fort Worth", | ||
"Dallas", | ||
"Jacksonville", | ||
"Columbus", | ||
"Charlotte", | ||
], | ||
"Salary": [ | ||
70000, | ||
100000, | ||
90000, | ||
80000, | ||
110000, | ||
130000, | ||
140000, | ||
160000, | ||
120000, | ||
170000, | ||
180000, | ||
150000, | ||
190000, | ||
200000, | ||
210000, | ||
], | ||
} | ||
|
||
df = pd.DataFrame(data) | ||
|
||
elements = [cl.Dataframe(data=df, display="inline", name="Dataframe")] | ||
|
||
await cl.Message(content="This message has a Dataframe", elements=elements).send() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { runTestServer } from '../../support/testUtils'; | ||
|
||
describe('dataframe', () => { | ||
before(() => { | ||
runTestServer(); | ||
}); | ||
|
||
it('should be able to display an inline dataframe', () => { | ||
// Check if the DataFrame is rendered within the first step | ||
cy.get('.step').should('have.length', 1); | ||
cy.get('.step').first().find('.MuiDataGrid-main').should('have.length', 1); | ||
|
||
// Click the sort button in the "Age" column header to sort in ascending order | ||
cy.get('.MuiDataGrid-columnHeader[aria-label="Age"]') | ||
.find('button') | ||
.first() | ||
.click({ force: true }); | ||
// Verify the first row's "Age" cell contains '25' after sorting | ||
cy.get('.MuiDataGrid-row') | ||
.first() | ||
.find('.MuiDataGrid-cell[data-field="Age"] .MuiDataGrid-cellContent') | ||
.should('have.text', '25'); | ||
|
||
// Click the "Next page" button in the pagination controls | ||
cy.get('.MuiTablePagination-actions').find('button').eq(1).click(); | ||
// Verify that the next page contains exactly 5 rows | ||
cy.get('.MuiDataGrid-row').should('have.length', 5); | ||
|
||
// Click the input to open the dropdown | ||
cy.get('.MuiTablePagination-select').click(); | ||
// Select the option with the value '50' from the dropdown list | ||
cy.get('ul.MuiMenu-list li').contains('50').click(); | ||
// Scroll to the bottom of the virtual scroller in the MUI DataGrid | ||
cy.get('.MuiDataGrid-virtualScroller').scrollTo('bottom'); | ||
// Check that tha last name is Olivia | ||
cy.get('.MuiDataGrid-row') | ||
.last() | ||
.find('.MuiDataGrid-cell[data-field="Name"] .MuiDataGrid-cellContent') | ||
.should('have.text', 'Olivia'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.