I am building a web app using Python Shiny, I am trying to create a toggle switch such that one can change the app theme by turning it on and off. The challenge I am facing is that the theme changes when you click on it once, with subsequent clicks it just remains constant and refuses to change. I don't know if it has something to do with my code. Here is my code below
import shinyswatch
from shiny import App, Inputs, Outputs, Session, render, ui, reactive
import pandas as pd
sales = pd.read_csv("data/sales_data.csv")
warehouse_option = sales["warehouse"].unique().tolist()
product_option = sales["product_line"].unique().tolist()
app_ui = ui.page_fluid(
ui.page_navbar(
ui.nav(
"Sales Dashboard",
ui.output_ui("theme"),
ui.layout_sidebar(
ui.panel_sidebar(
ui.input_switch("theme_toggle", "Change Theme"),
ui.input_selectize("warehouse", "Select Warehouse", warehouse_option),
ui.input_selectize("product", "Select Product Line", product_option)
),
ui.panel_main(
)
)
),
ui.nav(
"Model Prediction"
)
)
)
def server(input, output, session):
@output
@render.ui
def theme():
x = input.theme_toggle()
if x == True:
return shinyswatch.theme.vapor()
else:
return shinyswatch.theme.lux()
app = App(app_ui, server)
Here are images showing the theme changing, but the switch only changes the theme once and that's all. Light Theme and Dark Theme