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

Display Cell Colors in a Dataframe #2688

Closed
1 task done
Tracked by #1201
freddyaboulton opened this issue Nov 21, 2022 · 12 comments · Fixed by #5877
Closed
1 task done
Tracked by #1201

Display Cell Colors in a Dataframe #2688

freddyaboulton opened this issue Nov 21, 2022 · 12 comments · Fixed by #5877
Assignees
Labels
💾 Dataframe enhancement New feature or request needs designing The proposed feature needs to be discussed and designed before being implemented

Comments

@freddyaboulton
Copy link
Collaborator

freddyaboulton commented Nov 21, 2022

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
In pandas, you can use the style property to apply formatting to your data (cell background colors, rounding decimals) and then get an HTML representation of the table.

Gradio developers can display this data with the HTML component but at that point you loose the ability to add/remove/edit cells and sort by cell contents.

It would be better if the dataframe component could take in the style defined on the backend.

Describe the solution you'd like

The gr.DataFrame component takes the output of the pandas.style method.

Open to other suggestions for how to support the colored cell case.

Additional context
Came up during the Data Measurements project (huggingface/data-measurements-tool#45)

@freddyaboulton freddyaboulton added enhancement New feature or request needs designing The proposed feature needs to be discussed and designed before being implemented labels Nov 21, 2022
@freddyaboulton
Copy link
Collaborator Author

Need to work on this soon as more people have asked about it (@sashavor)

@pngwn
Copy link
Member

pngwn commented Feb 22, 2023

I don't think this is the right approach because it won't work with themes.

Does pandas have a way of semantically labelling cells? Stuff like the formatting of contents is fine but not things like colors. I understand the need to 'highlight' certain fields or rows/ cols but i think it should be framed in that way. If we need our own API for this then I think that is okay too, if it is possible.

@freddyaboulton
Copy link
Collaborator Author

The use case I've seen for this is creating heatmaps for your data. This is how the pandas syntax works right now, you basically pass a colormap that gets applied to a subset of columns that you choose.

This is the pandas syntax:

import pandas as pd
import numpy as np

rs = np.random.RandomState(0)
df = pd.DataFrame(rs.rand(10, 10))
corr = df.corr()
corr.style.background_gradient(cmap='coolwarm')

image

Are you suggesting the color map be included in the theme in the theme api?

@pngwn
Copy link
Member

pngwn commented Feb 22, 2023

That is a very good question. It would certainly be cool if 'official' themes actually supported a set of visualisation palettes. Which has now reminded me of that issue that I forgot about: #2780

@abidlabs abidlabs added this to the Component Cleanup milestone Jul 9, 2023
@freddyaboulton
Copy link
Collaborator Author

Just got another request for this here: https://discord.com/channels/879548962464493619/1139122387921666048

@abidlabs abidlabs removed this from the Component Cleanup milestone Aug 10, 2023
@sedrick-keh-tri
Copy link

+1 on this. Would be very helpful to have this!

@abidlabs abidlabs added this to the Component Cleanup milestone Aug 21, 2023
@abidlabs abidlabs self-assigned this Aug 21, 2023
@abidlabs
Copy link
Member

@sedrick-keh-tri we're working on implementing this -- would be very helpful if you can share what your use case is for adding color to cells, specifically how you intend the colors to be specified. Are you coloring based on the data in each cell for example? Or are you specifying the color of each cell yourself?

@sedrick-keh-tri
Copy link

More of the latter. I have a table and I would like to highlight certain rows for emphasis

@abidlabs
Copy link
Member

And is it a dataframe that you're planning on editing interactively afterwards or just statically to display content?

@sedrick-keh-tri
Copy link

Statically display content

@0-hero
Copy link

0-hero commented Oct 1, 2023

+1 Would be very helpful to have this. Any ETA on this feature?

@abidlabs
Copy link
Member

abidlabs commented Oct 2, 2023

We have an open PR but it still needs a bit of work. Please follow #5569 to keep up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💾 Dataframe enhancement New feature or request needs designing The proposed feature needs to be discussed and designed before being implemented
Projects
None yet
5 participants