shadshiny’s look is entirely token-driven. Every colour, radius, and surface is a CSS custom property, so theming means overriding properties – never editing component CSS or hard-coding hex values.
The token system
Colours are OKLCH --shad-* custom properties defined on
the page root, for example --shad-background,
--shad-foreground, --shad-primary,
--shad-muted, --shad-border,
--shad-ring. Components reference these tokens exclusively.
To restyle, set the token – not the element.
/* your own CSS, included via page_shad(..., tags$head(...)) or a www/ file */
:root {
--shad-primary: oklch(0.55 0.22 265);
--shad-radius: 0.75rem;
}Because everything keys off the same variables, one override cascades through every component consistently in both light and dark mode.
The twelve presets
shadshiny ships twelve palettes. Seven are full neutral ramps that recolour every surface, border and text token: slate, stone, zinc, mauve, olive, mist, taupe. Five are accents that keep the neutral surfaces and change the primary colour, focus ring and chart series: blue, green, rose, violet, orange. Choose one at the page level:
Presets are applied through a data-shad-theme attribute
on the page root, so they compose with – rather than replace – your
custom token overrides.
Scope a preset to one subtree when the rest of the page should keep its current palette:
shad_theme_preset(
"green",
shad_card(shad_card_content("Only this card uses the green preset."))
)Dark mode
Dark mode keys off .dark and
[data-bs-theme="dark"] on an ancestor. That second signal
is exactly what bslib::input_dark_mode() toggles, so a
bslib dark-mode switch drives shadshiny components with zero extra
wiring:
library(shiny)
library(bslib)
library(shadshiny)
page_shad(
input_dark_mode(), # toggles [data-bs-theme]; shadshiny follows
shad_card(shad_card_content(shad_p("I recolour automatically.")))
)You can also force a mode at page level:
page_shad(dark = TRUE, ...) # start in dark modeDirectionality
page_shad() accepts ordinary HTML attributes through
..., so an RTL page does not add a new R API argument:
The runtime keeps floating panels and other body portals synchronized
with the nearest dir and lang owner, including
direction changes made after the page loads. Layout spacing, borders,
and alignment use CSS logical properties; physical coordinates remain
explicit where a component’s named side is a geometry contract. For user
content that can mix scripts, opt into browser script detection with
dir = "auto" on the content wrapper, message content, or
data-table root (for example,
shad_data_table("tbl", data, dir = "auto")).
Changing theme at runtime
update_shad_theme() swaps the preset and/or dark state
live from the server – ideal for a settings toolbar built from a
shad_select() and a shad_switch():
ui <- page_shad(
shad_select("preset", label = "Theme",
choices = c("slate", "stone", "zinc", "mauve", "olive",
"mist", "taupe", "blue", "green", "rose",
"violet", "orange"),
selected = "slate"),
shad_switch("dark", label = "Dark mode")
)
server <- function(input, output, session) {
observe({
update_shad_theme(preset = input$preset, dark = input$dark)
})
}Custom themes
The presets are a starting point, not a ceiling.
shad_theme() builds a palette in R: name the tokens you
care about, leave the rest to the base.
brand <- shad_theme(
primary = "#7c3aed",
primary_foreground = "#ffffff",
radius = "0.75rem",
font_sans = "Inter, system-ui, sans-serif",
chart = c("#7c3aed", "#06b6d4", "#f59e0b", "#ef4444"),
dark = list(primary = "#a78bfa", background = "oklch(0.16 0.02 285)")
)
ui <- page_shad(theme = brand, ...)Colours may be hex ("#7c3aed"), rgb(), a
named CSS colour, or OKLCH ("oklch(0.55 0.24 285)") –
everything is normalised on the way in. dark = takes a list
of the same token names, applied only under .dark; tokens
you don’t name there inherit the light value, which is almost never what
you want for background and foreground.
The named arguments cover the common tokens (primary,
background, foreground, card,
muted, accent, destructive,
border, input, ring,
radius, font_sans, font_mono, and
their *_foreground pairs). Anything else – including the
--shad-sidebar-* family – goes through ...
with the --shad- prefix dropped:
shad_theme(primary = "#7c3aed", `sidebar-background` = "oklch(0.98 0.01 285)")Scoping a theme
theme = on page_shad() themes the whole
page. To theme one region instead, wrap it:
shad_theme_scope(
brand,
shad_card(shad_card_content("Only this subtree uses `brand`."))
)shad_theme_scope() mints a private class and emits the
CSS for it, so nested scopes compose and nothing leaks out.
Importing from the shadcn registry
The shadcn theme registry
publishes themes as JSON. shad_theme_from_registry() maps
their token names onto shadshiny’s and hands you back a
shad_theme(). The import is experimental: the registry
schema belongs to upstream and may move.
tw <- shad_theme_from_registry("https://tweakcn.com/r/themes/some-theme.json")
ui <- page_shad(theme = tw, ...)It takes a URL or a local path. Unmapped tokens are dropped rather than guessed, so a registry theme built for a much newer shadcn will land, minus whatever shadshiny has no slot for.
Switching a custom theme at runtime
update_shad_theme(theme = ) takes a
shad_theme() just like preset = takes a preset
name, and theme = NA clears back to the page’s own:
observeEvent(input$brand_on, update_shad_theme(theme = brand))
observeEvent(input$brand_off, update_shad_theme(theme = NA))Reading the tokens back
shad_tokens(preset, dark) returns the resolved token
set, and shad_chart_colors(n, preset, dark) the chart ramp
as hex – both useful when you need to hand a colour to something that
isn’t CSS, like a plot. See vignette("charts").
Hand-written CSS
You never have to use shad_theme(). The tokens are
ordinary custom properties, so plain CSS works. The sidebar family has
its own --shad-sidebar-* tokens
(--shad-sidebar-background,
--shad-sidebar-foreground,
--shad-sidebar-border, …) so you can give navigation a
distinct surface:
:root {
--shad-sidebar-background: oklch(0.98 0.01 265);
}
.dark {
--shad-sidebar-background: oklch(0.20 0.02 265);
}Override under both the light selector and .dark to keep
the two modes in step.