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

Help Dynamically Inserting and Removing Nav_Panel Tabs #1510

Open
devdan852 opened this issue Jul 9, 2024 · 0 comments
Open

Help Dynamically Inserting and Removing Nav_Panel Tabs #1510

devdan852 opened this issue Jul 9, 2024 · 0 comments

Comments

@devdan852
Copy link

devdan852 commented Jul 9, 2024

Hello! I am currently using Shiny for Python to design an application that dynamically creates and removes tabs with the press of an input_task_button. When clicking on the newly generated tab, the intent is to switch to that tab and generate more UI content based on what the user selects in an accordion_panel. I haven't gotten to that part yet but my code is outlined below

from shiny import App, Inputs, Outputs, Session, reactive, render, ui
from shinywidgets import output_widget, render_widget

app_ui = ui.page_fluid(
    ui.navset_tab(
        ui.nav_panel("Home",
              ui.card(
                          ui.card_header("Overview"),
                          ui.p("This is the landing page"),
                          ui.input_task_button(id = "create_tab",
                                               label = "Create New Tab",
                                               width = "400px",
                                               type = "success"),
                                )
                            )
        id = "shiny_tabs"
    )
)

def server(input, output, session):

    # Set reactive values
    tabs_created = reactive.value(1)

     # Generate tabs
     @reactive.Effect
     @reactive.event(input.create_tab)
     def _():
          tab_title = f"View {tabs_created.get()}"
          ui.insert_ui(
              ui.navset_tab(
                  ui.nav_panel(tab_title,
                                       ui.modal("This will include the accordion content")
                                      )
                  ),
                  selector = "#shiny_tabs",
                  where = "beforeEnd"
          )
          
          tabs_created.set(tabs_created.get() + 1)
          
app = App(app_ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant