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

Ensure paginate updates when samples value changes in Dataset #7761

Merged
merged 2 commits into from Mar 21, 2024

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Mar 20, 2024

Description

We weren't updating the paginate value in the Dataset component, so I've we dynamically populated the value of samples, the paginate bool would still be false. This PR adds reactivity logic to the paginate value.

❓ Shall I add an e2e test for Dataframe in this PR?

To test, run the following demo and click "get samples". Check the pagination works as expected in the dynamically updated Dataset.

import gradio as gr

def get_samples():

    samples = [['1'],['2'],['3'],['4'],['5'],['6'],['7'],['8'],['9'],['10']]
    return samples

with gr.Blocks() as demo:
    with gr.Row(variant='panel'):
        with gr.Column():
            ds_tbox = gr.Textbox(label='Example Name', visible=False)
            samples_ds = gr.Dataset(components=[ds_tbox], headers=['Samples'],label='Sample Questions', samples=get_samples(),samples_per_page=5)
        with gr.Column():
            examples_name_tbox = gr.Textbox(label='Examples Name', visible=False)
            examples_ds = gr.Dataset(components=[examples_name_tbox], headers=['NIL Questions'],
                                     label='Example Questions - click to select', samples='', samples_per_page=5)
    with gr.Row():
        get_examples_btn = gr.Button(value="Get Examples")
        get_examples_btn.click(fn=get_samples,inputs=None, outputs=examples_ds)

if __name__ == "__main__":
  demo.launch()

Closes: #7303

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 20, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website building...
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/83de71c0549ae85a6022eeb5d9d414a33bef8678/gradio-4.22.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 20, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Ensure paginate updates when samples value changes in Dataset

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.

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look good to me @hannahblair !

I think a test would be nice but imo this is a small bug so not sure we need a whole e2e just for this functionality.

@hannahblair
Copy link
Collaborator Author

@freddyaboulton Yeah, we don't actually have any tests in place for the Dataset right now, so I'm going to leave writing tests for this until I have the bandwidth

@hannahblair hannahblair merged commit ca42748 into main Mar 21, 2024
11 checks passed
@hannahblair hannahblair deleted the dataset-update-paginate branch March 21, 2024 15:12
@pngwn pngwn mentioned this pull request Mar 20, 2024
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.

If gr.Dataset() isn't initialized with data on launch, pagination doesn't work
3 participants