Dark Mode Switch
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [viewer]
#| viewerHeight: 200
## file: app.py
from shiny import ui, render, App
app_ui = ui.page_fluid(ui.input_dark_mode()).add_class("h-100 w-100 align-content-center text-center")
def server(input, output, session):
pass
app = App(app_ui, server)
Relevant Functions
-
ui.input_dark_mode
ui.input_dark_mode(id=None, mode=None, **kwargs)
Details
A dark mode switch input toggles the app between dark and light modes.
To add a dark mode switch to your app:
Add
ui.input_dark_mode()
to the UI of your app to create a dark mode switch. Where you call this function will determine where the dark mode switch will appear within the app’s layout.Optionally, specify the
id
parameter ofui.input_dark_mode()
to define the identifier of the switch. Whenid
is specified, you can use it to access the current color mode.By default, the user’s system settings for the preferred color scheme will be used for the initial mode of the app. To force the initial mode, set the
mode
parameter to"light"
or"dark"
.
The value of an input component is accessible as a reactive value within the server()
function. To access the value of a dark mode switch:
- Use
input.<dark_mode_switch_id>()
(e.g.,input.mode()
) to access the value of the dark mode switch. The server value of a dark mode switch is a string: either"light"
or"dark"
.