Hello! I am encountering a peculiar issues in my Shiny app where after I press the "+" button in my list of tabs, all the input and output values from prior tabs are reset/wiped. Is there a way to preserve the input and output values regardless of the number of times I generate a new tab?
My code is outlined as follows:
from shiny import App, Inputs, Outputs, Session, module, reactive, render, ui
# Create a Module UI
@module.ui
def textbox_ui(panelNum):
return ui.nav_panel(
f"Tab {panelNum}",
ui.input_text_area(id=f"test_text",
label = "Enter some text"),
ui.output_ui(f"display_text_{panelNum}"),
value = f"Tab_{panelNum}"
)
# Set up module server
@module.server
def textbox_server(input, output, session, panelNum):
@output(id=f"display_text_{panelNum}")
@render.text
def return_text():
return input[f"test_text"]()
# Set up app UI
app_ui = ui.page_fluid(
ui.h2('Test App', align='center', fillable=True),
ui.output_ui("tab_UI"),
title = "Test App"
)
# Set up server
def server(input, output, session):
# Set up reactive values
navs = reactive.value(0)
# Add tabs if the user presses "+"
@reactive.effect
@reactive.event(input.shiny_tabs)
def add_tabs():
if input.shiny_tabs() == "+":
navs.set(navs.get() + 1)
@output
@render.ui
def tab_UI():
[textbox_server(str(x), panelNum=x+1) for x in range(navs.get())]
ui.update_navs("shiny_tabs", selected = f"Tab_{navs.get()}")
return ui.navset_tab(
ui.nav_panel("Home",
ui.card(
ui.card_header("Overview"),
ui.p("An example of the outputs clearing")
),
value = "panel0"
),
*[textbox_ui(str(x), panelNum=x+1) for x in range(navs.get())],
ui.nav_panel("+"),
id = "shiny_tabs"
)
app = App(app_ui, server)
Thanks for looking into it!