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

Fix for stylized DataFrame #6318

Merged
merged 2 commits into from
Nov 7, 2023
Merged

Fix for stylized DataFrame #6318

merged 2 commits into from
Nov 7, 2023

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Nov 7, 2023

Fixes a regression: #6315

Sample code:

import pandas as pd 
import gradio as gr

# Creating a sample dataframe
df = pd.DataFrame({
    "A" : [14, 4, 5, 4, 1], 
    "B" : [5, 2, 54, 3, 2], 
    "C" : [20, 20, 7, 3, 8], 
    "D" : [14, 3, 6, 2, 6], 
    "E" : [23, 45, 64, 32, 23]
}) 

# Applying style to highlight the maximum value in each row
styler = df.style.highlight_max(color = 'lightgreen', axis = 0)

# Displaying the styled dataframe in Gradio
with gr.Blocks() as demo:
    gr.DataFrame(styler)
    
demo.launch()

Explanation: the introduction of

		on:change={(e) => (value = e.detail)}

was causing an infinite loop when working with metadata. This fixes it, but as I'm not sure if this is the best fix, feel free to suggest an alternative. But basically here, we check to see if a Dataframe is interactive before updating the value. I've tested with matrix_transpose, which continues to work.

I also added a functional test since neither the backend nor the frontend tests alone caught this.

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Nov 7, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/d6efc43171ece506ce41ad8601142553efaa7f56/gradio-4.1.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@d6efc43171ece506ce41ad8601142553efaa7f56#subdirectory=client/python"

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Nov 7, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/dataframe minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix for stylized DataFrame

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs abidlabs marked this pull request as ready for review November 7, 2023 15:08
@abidlabs abidlabs requested review from aliabid94 and aliabd November 7, 2023 15:13
@hannahblair
Copy link
Collaborator

hannahblair commented Nov 7, 2023

Works for me!

Screenshot 2023-11-07 at 17 51 58

edit: i'm trying to work out why this would break it though 🤔

@abidlabs
Copy link
Member Author

abidlabs commented Nov 7, 2023

Thanks @hannahblair I'll merge this in so that we can get a release out with the fix. Let me know if you can figure out why this fix was needed (cc @pngwn as well)

@abidlabs abidlabs merged commit d3b53a4 into main Nov 7, 2023
@abidlabs abidlabs deleted the fix-colorful-df branch November 7, 2023 19:16
@pngwn pngwn mentioned this pull request Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants