-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow users or third-party packages to replace Bootstrap CSS #1270
Comments
I feel uneasy about having an exported Also, I can't help but feel like In fact, I'm starting to question whether we need __all__ = (
"bootstrap_css",
)
def bootstrap_css(path: Path | str, check_version: bool = True) -> tuple[Tag | HTMLDependency]:
# Snoop the version of the Bootstrap CSS file
if check_version:
check_bootstrap_version(path)
return (
ui.include_css(path),
HTMLDependency(
name="bootstrap-css", version=bootstrap_version
),
)
def check_bootstrap_version(path: Path | str):
file_path = check_path(path)
content = read_utf8(file_path)
# TODO: extract version from Bootstrap's banner, then warn/err if not compatible, and
# also warn if the version wasn't found?
def bootstrap_deps() -> list[HTMLDependency]:
return [
jquery_deps(),
HTMLDependency(
name="bootstrap-js",
version=bootstrap_version,
source={"package": "shiny", "subdir": "www/shared/bootstrap/"},
script={"src": "bootstrap.bundle.min.js"},
meta={"name": "viewport", "content": "width=device-width, initial-scale=1"},
),
HTMLDependency(
name="bootstrap-css",
version=bootstrap_version,
source={"package": "shiny", "subdir": "www/shared/bootstrap/"},
stylesheet={"href": "bootstrap.min.css"}
)
] Two things to note about this approach:
|
In this case, I agree, we wouldn't want to add a |
theme
argument to page_*()
functions
#1282 shows what @cpsievert can you take a look at the approach? This iteration has a bit more moving pieces, e.g. changes in shinyswatch are required posit-dev/py-shinyswatch#32, and it'd be good to hear your opinion before I get too far down the road. Note that we don't need to make |
Coming back to this after a bit, I'm not seeing a clear winner between the two proposals.
To summarize the current state of affairs, the core work to be done is to separate the Bootstrap dependencies into CSS and JS components. Having done that, third-party theme providers can focus on providing only the Bootstrap CSS (and possibly on suppressing the built-in CSS). In other words, at a basic level, everything we need can be accomplished via htmltools dependency handling. On the other hand, a htmltools-dependency-only approach pushes run-time Bootstrap compatibility checks into third-party packages. I think it would be better for most of the abstractions to live in As pointed out in https://github.com/posit-dev/py-shiny/pull/1282/files#r1552096813 the htmltools-dependency-only approach also needs to account for multiple calls to a function like We could certainly do a mixture of both -- which would mean adding a If we take the mixed approach, though, we'll need to agree on the shape of the data passed into |
Another, radically more simple option from @cpsievert: the |
It'd be nice to have an |
In Shiny for R, all page functions take a
theme
argument, with the following behavior:NULL
, use Bootstrap 3<link>
element to the page<head>
. Note that base Bootstrap 3 is still included in this case.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:theme=MISSING
ordefault casetheme=ui.theme()
theme: str | Path
ui.include_css(theme)
to include the CSS file. Shiny's Bootstrap bundle is still added, but without including the Bootstrap stylesheet.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.replace
s the"css"
of Shiny's Bootstrap bundle, the entire ("all"
) Bootstrap bundle, or the theme is overlaid over base Bootstrap ("none"
).theme
could also be a dict with keystheme
,bs_version
,replace
such thatui.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 aTheme
orShinyTheme
instance.The text was updated successfully, but these errors were encountered: