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

DataFrame styling doesn't work when it's used as input to another component #9938

Closed
1 task done
x-tabdeveloping opened this issue Nov 11, 2024 · 4 comments
Closed
1 task done
Labels
bug Something isn't working pending clarification

Comments

@x-tabdeveloping
Copy link

Describe the bug

When you format a dataframe with pandas Styles, and then use them in gr.DataFrame, the style only applies if the dataframe is not used as input to callbacks or other components.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

If I do this:

import gradio as gr
import gradio as gr
import pandas as pd

df = (
    pd.DataFrame(
        {
            "values": [
                1.333333333333333,
                2.44444444444444444,
                3.55555555555555555,
                6.77777777777777777,
            ],
            "other_values": [
                1.333333333333333,
                2.44444444444444444,
                3.55555555555555555,
                6.77777777777777777,
            ],
        }
    )
    .style.format({"values": "{:.2f}", "other_values": "{:.0f}"})
    .highlight_min("values")
    .highlight_max("other_values")
)

with gr.Blocks() as demo:
    data = gr.DataFrame(df)

demo.launch()

then the table is properly styled as expected:
image

If I add a Markdown component that takes the dataframe as its input, the styling disappears.

def create_text(df):
    n_rows = len(df.index)
    return f"# This is some markdown\nThere are {n_rows} rows in the dataframe"


with gr.Blocks() as demo:
    data = gr.DataFrame(df)
    gr.Markdown(create_text, inputs=[data])

image

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.5.0
gradio_client version: 1.4.2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.4.0
audioop-lts is not installed.
fastapi: 0.115.4
ffmpy: 0.4.0
gradio-client==1.4.2 is not installed.
httpx: 0.27.2
huggingface-hub: 0.26.1
jinja2: 3.1.3
markupsafe: 2.1.5
numpy: 1.25.2
orjson: 3.10.7
packaging: 24.0
pandas: 2.2.2
pillow: 10.3.0
pydantic: 2.7.0
pydub: 0.25.1
python-multipart==0.0.12 is not installed.
pyyaml: 6.0.1
ruff: 0.3.7
safehttpx: 0.1.1
semantic-version: 2.10.0
starlette: 0.41.2
tomlkit==0.12.0 is not installed.
typer: 0.12.5
typing-extensions: 4.11.0
urllib3: 2.2.1
uvicorn: 0.30.6
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.2.0
httpx: 0.27.2
huggingface-hub: 0.26.1
packaging: 24.0
typing-extensions: 4.11.0
websockets: 12.0


### Severity

Blocking usage of gradio
@Muennighoff
Copy link

This bug is pretty critical for the new MTEB leaderboard (an updated version of https://huggingface.co/spaces/mteb/leaderboard) - would be amazing if we could get thoughts from someone on the Gradio team (cc @abidlabs @pngwn @dawoodkhan82)

@abidlabs
Copy link
Member

abidlabs commented Nov 27, 2024

Apologies for the late reply, yes as indicated in the gr.Dataframe docs, the styling is only rendered if the interactive is False. And a gr.DataFrame is rendered as interactive=False by default unless it is used as an input in another event. However, you can also force it to be non-interactive, by setting interactive=False, e.g. in the original example:

def create_text(df):
    n_rows = len(df.index)
    return f"# This is some markdown\nThere are {n_rows} rows in the dataframe"


with gr.Blocks() as demo:
    data = gr.DataFrame(df, interactive=False)
    gr.Markdown(create_text, inputs=[data])

Does this work for you @Muennighoff @x-tabdeveloping?

@abidlabs
Copy link
Member

Going to close this as this is intended behavior, but lmk if there's still an issue here @Muennighoff @x-tabdeveloping

@abidlabs abidlabs closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
@x-tabdeveloping
Copy link
Author

Thanks for your reply, formatting does, indeed work again, when I specify interactive=False. It would be nice to have some indication of this behaviour in the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending clarification
Projects
None yet
Development

No branches or pull requests

3 participants