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

Add height param to gr.JSON #9023

Merged
merged 29 commits into from
Aug 13, 2024
Merged

Add height param to gr.JSON #9023

merged 29 commits into from
Aug 13, 2024

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Aug 6, 2024

Description

I initially implemented height as a param but we have a lines param in gr.Code, so it makes some sense to keep them fairly consistent.

I also added the lines param description in gr.Code that was missing, and added a tiny css tweak to handle big line numbers.

Closes: #8982

🎯 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
Collaborator

gradio-pr-bot commented Aug 6, 2024

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/6f28d395ea709c5efb5e9a99a901774a6ccc1dcd/gradio-4.41.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/6f28d395ea709c5efb5e9a99a901774a6ccc1dcd/gradio-client-1.5.0.tgz

gradio/components/code.py Outdated Show resolved Hide resolved
@abidlabs
Copy link
Member

abidlabs commented Aug 7, 2024

This works well @hannahblair! But I'm wondering if height might actually be better for two reasons:

(1) The behavior of lines is based on the number of lines of code that the json value takes up when it is rendered in the component, which may not necessarily be the same as the line numbers and could be confusing to users. For example, here I set lines to 10 but the json is only displayed to line 7, since line 2 takes up three lines in the display:

image

(2) lines in gr.Code actually behaves differently as commented above. So this parameter would be more like the max_lines parameter in gr.Textbox or the height parameter that we have in most of our other components

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Aug 7, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Add height param to gr.JSON

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.

@hannahblair
Copy link
Collaborator Author

makes perfect sense @abidlabs! thanks for explaining. i've made the changes :)

@hannahblair hannahblair changed the title Add lines param to gr.JSON Add height param to gr.JSON Aug 12, 2024
Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

LGTM @hannahblair! The height parameter looks good.

One thing I noticed while testing is that the JSON component, when empty, has its icon pinned to the top:

image

Unlike the other components, which center the icon vertically:

image

Although its not related to this PR, we could perhaps fix it here? Also fine to handle separately

@hannahblair hannahblair enabled auto-merge (squash) August 13, 2024 09:48
@hannahblair hannahblair merged commit 87e3537 into main Aug 13, 2024
18 checks passed
@hannahblair hannahblair deleted the json-height-param branch August 13, 2024 09:49
This was referenced Aug 13, 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.

The gr.JSON requires the lines parameter.
4 participants