Skip to content

Allow users or third-party packages to replace Bootstrap CSS #1270

@gadenbuie

Description

@gadenbuie

In Shiny for R, all page functions take a theme argument, with the following behavior:

  • If NULL, use Bootstrap 3
  • If a scalar string, assume it's a client-side path to a CSS file and add a <link> element to the page <head>. Note that base Bootstrap 3 is still included in this case.
  • If a bslib theme, add bslib::bs_theme_dependencies(theme) but not the base Bootstrap dependency after registering the theme (so that it can be used for runtime Sass compilation).

I'm proposing the following approach to theme in Python:

  1. theme=MISSING or theme=ui.theme() default case
    • Uses the default Shiny Bootstrap theme.
  2. theme: str | Path
    • Uses ui.include_css(theme) to include the CSS file. Shiny's Bootstrap bundle is still added, but without including the Bootstrap stylesheet.
  3. theme=ui.theme(
        theme: str | HTMLDependency | Tagifiable,
        bs_version: Optional[str],
        replace = "css" | "all" | "none"
    )
    
    • Allows a CSS file, HTML dependency or a tagifiable that returns an HTML dependency to provide the theme.
    • Includes optional bs_version that can be used for runtime checks to warn if the provided Bootstrap theme is out-of-date with Shiny's provided Bootstrap version.
    • Allows theme providers to determine if the theme replaces the "css" of Shiny's Bootstrap bundle, the entire ("all") Bootstrap bundle, or the theme is overlaid over base Bootstrap ("none").
  4. For completeness, theme could also be a dict with keys theme, bs_version, replace such that ui.theme(**dict) returns a full theme object.

The first two cases can be seen as a short-cut for providing ui.theme(), which itself returns a Theme or ShinyTheme instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions