Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a pandas dataframe element #1350

Open
tituslhy opened this issue Sep 17, 2024 · 6 comments
Open

Include a pandas dataframe element #1350

tituslhy opened this issue Sep 17, 2024 · 6 comments

Comments

@tituslhy
Copy link

Is your feature request related to a problem? Please describe.
Chainlit offers many elements that can be tagged to a message. I would like to suggest loading a pandas dataframe element because the response of LLMs can be made more neat with a table.

Describe the solution you'd like
Inclusion of a pandas dataframe element.

Describe alternatives you've considered
Streamlit has this feature https://docs.streamlit.io/develop/api-reference/data/st.dataframe

It would be great if chainlit has it too.

@hadarsharon
Copy link

Unfortunately you are not the first to have requested this feature.
For now I can only suggest using something like this (assuming your dataframe is stored in a variable df):

await cl.Message(
    content="Data Table",
    elements=[cl.Text(content=df.to_markdown(index=False), display="inline")],
).send()

I also believe native support for DataFrames should be added, just like in Streamlit, because Markdown tables don't look half as good and aren't interactive.
I've also tried something similar with df.to_html and language="html" in the cl.Message element, but:

  1. It requires rendering unsafe HTML which is a potential security concern
  2. Still doesn't look that nice, not like Streamlit at least

@desertproject
Copy link

I'm currently working on a draft pull request to implement this feature. The implementation will utilize the MUI X Data Grid component. I'll update this issue with more details and a link to the PR once it's available for feedback.

@desertproject
Copy link

Example

Screenshot 2024-09-24 at 17-14-02 Screenshot

@tituslhy
Copy link
Author

Looks great!

@tituslhy
Copy link
Author

Can I check if users can interact with the data frame like in streamlit - if they click the column name does it sort the data frame?

@desertproject
Copy link

Can I check if users can interact with the data frame like in streamlit - if they click the column name does it sort the data frame?

Yes, users can interact with the data frame similarly to how they would in Streamlit, including clicking the column name to sort it. You can explore additional interactive features and functionalities in this library here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants