Skip to content

Commit

Permalink
add workaround demo for shinyswatch theme picker error
Browse files Browse the repository at this point in the history
  • Loading branch information
sebovzeoueb committed Feb 20, 2025
1 parent 513b057 commit 2640cff
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions demo_projects/shinyswatch_error/workaround.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from shiny import App, ui, Inputs, Outputs, Session, reactive, render
import shinyswatch

app_ui = ui.page_auto(
ui.output_ui("main_page"),
ui.input_action_button("change_nav", "Change Nav"),
theme=shinyswatch.theme.darkly,
)


def server(input: Inputs, output: Outputs, session: Session):
nav_state = reactive.value(1)

@reactive.calc
def nav_items():
return [
ui.nav_panel(f"Page{i}", ui.markdown(f"# Page{i}"))
for i in range(nav_state.get())
]

@render.ui
def main_page():
shinyswatch.theme_picker_server()
return ui.navset_pill_list(
*nav_items(), ui.nav_control(shinyswatch.theme_picker_ui())
)

@reactive.effect
@reactive.event(input.change_nav)
def change_state():
nav_state.set(1 if nav_state.get() == 2 else 2)


app = App(app_ui, server)

0 comments on commit 2640cff

Please sign in to comment.