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
Be able to set the active Tab
programmatically
#2412
Comments
Hi @vzakharov this possible by using the Read more about state here: https://gradio.app/state_in_blocks/ If this solves your use case, feel free to close the issue. Otherwise, please add more details on what you are trying to acheive. |
What I need is not store the selected tab, but select an tab based on a certain stored value. Say, you have tabs 'Training' and 'Inference'. The user first trains some model, then infers it. While the model isn't trained yet (say, stored status is 0), I want the Training tab to be open whenever the app is opened. But when the model is already trained (stored status is 1), I want the Inference tab to open. Hope this clarifies. Alternatively, I might just not have understood your previous answer :-) |
Ah okay yes I don't think we currently support that. Out of curiosity, how would you get the stored status of the model? |
Tab
programmatically
Via Blocks.load() and then either get it from the server or localStorage. Currently the workaround I came up with is to use a group of Radios (indicating the stage) together with Boxes that become visible or hidden depending on the stage. Doesn’t look as neat but does the job. |
@abidlabs any progress? |
As @TashaSkyUp has kindly fixed in #2971, this is actually possible now @vzakharov. Here's a quick code snippet showing how to do it: import gradio as gr
def change_tab():
return gr.Tabs.update(selected=1)
with gr.Blocks() as demo:
with gr.Tabs() as tabs:
with gr.TabItem("Train", id=0):
t = gr.Textbox()
with gr.TabItem("Inference", id=1):
i = gr.Image()
btn = gr.Button()
btn.click(change_tab, None, tabs)
demo.launch() |
When I switch tabs, the next page starts at the bottom. Thanks |
Hello, I'm trying to follow the recommendation from @abidlabs but I'm receiving this error: |
Hi @gaurikapse if you are using Gradio 4.x, then you no longer need to return So the above code would be: import gradio as gr
def change_tab():
return gr.Tabs(selected=1)
with gr.Blocks() as demo:
with gr.Tabs() as tabs:
with gr.TabItem("Train", id=0):
t = gr.Textbox()
with gr.TabItem("Inference", id=1):
i = gr.Image()
btn = gr.Button()
btn.click(change_tab, None, tabs)
demo.launch() |
Hey abidlabs, @abidlabs thx Alex |
not work |
Is your feature request related to a problem? Please describe.
I have different tabs for different stages in the process, and I’d like the app to “remember” where the user is now.
Describe the solution you'd like
Seems like adding an 'active' parameter for a Tab will solve it, although it will be a bit cumbersome because you'll need to set 'active' to False for one tab and to True for another.
Additional context
Perhaps having a Tabs component which would combine several tabs in one, along with 'active_tab' parameter would be a more sustainable solution. But it also probably requires much more development.
The text was updated successfully, but these errors were encountered: