Hello, I am trying to get my feet wet with shiny core for python. While I am not entirely new to shiny, having dabbled with rshiny a few years ago I was never proficient with it either, python is a totally different environment too. Anyways I am trying to figure out why ui.update_sidebar in my code isn't working so I recreated a minimal reprex in a new app.py file to see if I could figure out what I am doing wrong. Even in this minimal example I can't figure out what is wrong.
Basically I took the example code from the python shiny website to create a ui.navset_tab with a ui.page_sidebar, ui.input_action_button and ui.update_sidebar. I put an action button in the main window and set a @reactive.event to hide the sidebar when the action button is selected. This does not seem to work for some reason though. I guess I am doing something wrong but I can't figure out what.
from shiny import App, ui, reactive, render, Inputs, Outputs, Session
app_ui = ui.page_fluid(
ui.navset_tab(
ui.nav_panel("A", "Panel A content"),
ui.nav_panel("B", "Panel B content"),
ui.nav_panel("C", "Panel C content"),
ui.nav_menu(
"Other links",
ui.nav_panel("D", "Panel D content"),
"----",
"Description:",
ui.nav_control(
ui.a("Shiny", href="https://shiny.posit.co", target="_blank")
),
),
id="tab",
),
ui.page_sidebar(
ui.sidebar(sidebar="Sidebar", bg="#f8f8f8"),
"Main content",
#when the action_button is clicked the side Sidebar should be hidden
ui.input_action_button(id="action_button", label="Action", width="20%", show=True)
)
)
def server(input: Inputs, output: Outputs, session: Session):
#the action button should close the sidebar
@reactive.effect
@reactive.event(input.action_button)
def close_sidebar():
ui.update_sidebar(id="Sidebar", show=False)
app = App(app_ui, server)