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

Can the tab be redirected by clicking the button? #8156

Closed
coolboyqu opened this issue Apr 28, 2024 · 2 comments
Closed

Can the tab be redirected by clicking the button? #8156

coolboyqu opened this issue Apr 28, 2024 · 2 comments

Comments

@coolboyqu
Copy link

For example, if I choose Tab4 now, I would like to select Tab1 by clicking on a button or something else. Does Gradio currently have similar features?

@mussonero
Copy link

mussonero commented Apr 28, 2024

try this

import gradio as gr

def change_tab(id):
    return gr.Tabs(selected=id)

with gr.Blocks() as demo:
    with gr.Tabs() as tabs:
        with gr.TabItem("Train", id=0): #index is 0
            t = gr.Textbox()
        with gr.TabItem("Inference", id=1): #index is 1
            i = gr.Image()
    
    btn = gr.Button()
    # When the button is clicked, switch to Tab1 (index 1)
    btn.click(change_tab, gr.Number(1, visible=False), tabs)
            
demo.launch()

@abidlabs
Copy link
Member

Thanks @mussonero! Yes that's the correct approach for selecting tabs programmatically

@abidlabs abidlabs closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 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

No branches or pull requests

3 participants