You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's common to want to add a global sidebar to a navbar page and to have some content in that sidebar be displayed conditionally. With Shiny Core, you can create an app with this layout using the following code:
When id is provided, the current page title is reported at that input.{id}.
ui.panel_conditional() can use the value of the input, e.g. input.page === 'B', to display content only when nav_panel("B", ...) is displayed.
In Shiny Express, this pattern is not possible because users cannot set id via ui.page_opts(). In theory, they would need to provide a custom function to ui.page_opts(page_fn=) that passes id to shiny.ui.page_navbar().
fromshiny.expressimportinput, uifromfunctoolsimportpartialfromshiny.uiimportpage_navbardefpage_navbar_id(*args, **kwargs):
returnpage_navbar(*args, **kwargs, id="page")
## Doesn't workui.page_opts(title="App with navbar", fillable=True, page_fn=page_navbar_id)
## Does work, but can't set the page `id`# ui.page_opts(title="App with navbar", fillable=True)withui.sidebar(title="Settings"):
ui.input_select("data", "Data", ("A", "B", "C"))
withui.panel_conditional("input.page === 'Settings B'"):
ui.input_select("subset", "Subset for B", ("e", "f", "g"))
withui.nav_panel("A"):
"Page A content"withui.nav_panel("B"):
"Page B content"
It's common to want to add a global sidebar to a navbar page and to have some content in that sidebar be displayed conditionally. With Shiny Core, you can create an app with this layout using the following code:
shinylive.io example
There are three components:
ui.page_navbar()
needs theid
argument.id
is provided, the current page title is reported at thatinput.{id}
.ui.panel_conditional()
can use the value of the input, e.g.input.page === 'B'
, to display content only whennav_panel("B", ...)
is displayed.In Shiny Express, this pattern is not possible because users cannot set
id
viaui.page_opts()
. In theory, they would need to provide a custom function toui.page_opts(page_fn=)
that passesid
toshiny.ui.page_navbar()
.shinylive.io example
This doesn't work, however, because the special handling for the top-level
with ui.sidebar()
only happens whenpage_fn is None
.py-shiny/shiny/ui/_page.py
Lines 543 to 545 in 340858a
py-shiny/shiny/ui/_page.py
Line 556 in 340858a
Attempting to run the example above using
ui.page_opts(page_fn)
gives the following errorThe text was updated successfully, but these errors were encountered: