gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
32.41k stars 2.42k forks source link

allow setting `gr.Tab` visibility #2592

Closed vzakharov closed 8 months ago

vzakharov commented 1 year ago

Currently gr.Tab doesn’t seem to have a visible parameter, unlike most other components. This makes it impossible to hide a Tab depending on certain conditions

Say, in my Jukebox Web UI this could be hiding or showing “continue composing” tab depending on whether or not the very first sample has already been generated.

I wonder if it’s possible to add such a parameter?

pngwn commented 1 year ago

I don't think this is documented but if you use the full version of Tab instead of the shorthand then you can achieve this behaviour:

import gradio as gr

with gr.Blocks() as demo:
  with gr.Tabs() as tabs:
    with gr.TabItem("Tab 1"):
      ...
    with gr.TabItem("Tab 2"):
      ...

in this example tabs can be used as an output to an event and you can set the visible state. This will hide the whole tabbed interface, hiding an individual tab is not currently possible due to how tabs actually work. But we could try to make this work.

vzakharov commented 1 year ago

It’s good to know the full version, but yeah it doesn’t achieve the intended effect. Thanks for giving this a thought!

hithereai commented 1 year ago

Any updates on this one?

abidlabs commented 1 year ago

Not yet, the team has other competing priorities so it's likely we won't be able to get to this anytime soon. PRs are welcome!

pseudotensor commented 1 year ago

@abidlabs Yes, this has also been issue for me, hard to control gr.TabItem for specific flexible startup modes. So I just end up with dummy tab that has nothing in it, which is bad looking.

linuxonly801 commented 1 year ago

I don't think this is documented but if you use the full version of Tab instead of the shorthand then you can achieve this behaviour:

import gradio as gr

with gr.Blocks() as demo:
  with gr.Tabs() as tabs:
    with gr.TabItem("Tab 1"):
      ...
    with gr.TabItem("Tab 2"):
      ...

in this example tabs can be used as an output to an event and you can set the visible state. This will hide the whole tabbed interface, hiding an individual tab is not currently possible due to how tabs actually work. But we could try to make this work.

This works for me! (I only need to hide a tab, and never need to show it.) the codess are as follows:

with gr.Tabs(visible=False) as tabs:
    with gr.Tab('hide page'):
        ...
irgolic commented 1 year ago

This is a glaring issue if the recommended way to create a variable number of components is to create dummy ones and hide them.

dwipper commented 8 months ago

Good to know about the gr.Tabs visibility approach, although for my use case, it could get pretty complicated. My use case is to have a user profile that specifies which application tabs are displayed for a specific user. I could implement this with the gr.Tabs visibility, but given that I have 5+ tabs, that could result in upwards of 5 x 5 gr.Tabs "Templates" to turn the visibility on/off.....I am wondering if it would be possible to dynamically generate the set of tabs from individual "tab templates"? Thoughts anyone?