gradio icon indicating copy to clipboard operation
gradio copied to clipboard

Display Cell Colors in a Dataframe

Open freddyaboulton opened this issue 2 years ago • 1 comments

  • [ ] 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 (https://github.com/huggingface/data-measurements-tool/pull/45)

freddyaboulton avatar Nov 21 '22 17:11 freddyaboulton

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

freddyaboulton avatar Feb 16 '23 20:02 freddyaboulton

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.

pngwn avatar Feb 22 '23 11:02 pngwn

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?

freddyaboulton avatar Feb 22 '23 15:02 freddyaboulton

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

pngwn avatar Feb 22 '23 18:02 pngwn

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

freddyaboulton avatar Aug 10 '23 13:08 freddyaboulton

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

sedrick-keh-tri avatar Aug 16 '23 17:08 sedrick-keh-tri

@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?

abidlabs avatar Aug 21 '23 20:08 abidlabs

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

sedrick-keh-tri avatar Aug 21 '23 22:08 sedrick-keh-tri

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

abidlabs avatar Aug 21 '23 22:08 abidlabs

Statically display content

sedrick-keh-tri avatar Aug 21 '23 22:08 sedrick-keh-tri

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

0-hero avatar Oct 01 '23 03:10 0-hero

We have an open PR but it still needs a bit of work. Please follow https://github.com/gradio-app/gradio/pull/5569 to keep up to date.

abidlabs avatar Oct 02 '23 03:10 abidlabs