posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.2k stars 69 forks source link

[express]: how to put a sidebar in a `navset_card_tab()` context manager? #1507

Open Damonsoul opened 1 month ago

Damonsoul commented 1 month ago

With Shiny Core, you can create an app with this layout using the following code:

from shiny import App, ui

ui = ui.page_fluid(ui.navset_card_tab(
    ui.nav_panel("A", "Panel A content"),
    ui.nav_panel("B", "Panel B content"),
    title="Card with navbar",
    sidebar=ui.sidebar(
        ui.input_select("data", "Data", ("A", "B", "C"))
    ),
))

def server(input):
    pass

app = App(ui, server)

But when I try it in shiny.express using the following code it doesn't work

from shiny.express import ui
ui.page_opts(fillable=True)

with ui.navset_card_tab(title="Card with navbar"):  
    with ui.sidebar():
        ui.input_select("data", "Data", ("A", "B", "C"))
    with ui.nav_panel("A"):
        "Panel A content"
    with ui.nav_panel("B"):
        "Panel B content"
cpsievert commented 1 month ago

We will hopefully support that usage (of with ui.sidebar() inside with ui.navset_card_tab()), but in the meantime, you can workaround the limitation by passing a sidebar object to the sidebar keyword parameter