refactor: Avoid needing to directly inspect shiny's bootstrap_deps()#32
Merged
refactor: Avoid needing to directly inspect shiny's bootstrap_deps()#32
bootstrap_deps()#32Conversation
cpsievert
reviewed
Apr 4, 2024
cpsievert
reviewed
Apr 4, 2024
cpsievert
reviewed
Apr 4, 2024
This comment has been minimized.
This comment has been minimized.
cpsievert
reviewed
Apr 5, 2024
cpsievert
reviewed
Apr 5, 2024
cpsievert
reviewed
Apr 5, 2024
cpsievert
reviewed
Apr 5, 2024
cpsievert
reviewed
Apr 5, 2024
cpsievert
reviewed
Apr 5, 2024
cpsievert
reviewed
Apr 5, 2024
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
cpsievert
reviewed
Apr 8, 2024
Comment on lines
+41
to
+47
| def dep_shinyswatch_bootstrap_js() -> HTMLDependency: | ||
| return HTMLDependency( | ||
| name="shinyswatch-js", | ||
| version=bsw5_version, | ||
| source={"package": "shinyswatch", "subdir": bs5_path}, | ||
| script={"src": "bootstrap.bundle.min.js"}, | ||
| ) |
There was a problem hiding this comment.
Should this only be included for shiny <= 0.8.1?
Contributor
Author
There was a problem hiding this comment.
No, this PR still removes the Bootstrap JS dependency. We'll take that out in a follow up PR once shiny has some run-time Bootstrap compatibility checks. Then we'll require latest shiny in shinswatch.
cpsievert
approved these changes
Apr 8, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is pre-work for posit-dev/py-shiny#1282 to avoid errors in Shiny's test suite caused by shinyswatch's assumptions about the now changing structure of
bootstrap_deps().The primary goal is to avoid having to inspect the Bootstrap dependencies provided by Shiny. Instead, we suppress the
bootstrap,bootstrap-jsandbootstrap-cssdependencies in shinyswatch's html dependency.In posit-dev/py-shiny#1282, Shiny's Bootstrap dependency will switch to
bootstrap-js,bootstrap-cssandbootstrap-meta, which can be suppressed with a new helper functionshiny.ui._html_deps_external.bootstrap_deps_suppress().The goal of posit-dev/py-shiny#1282 is to introduce
shiny.ui.include_bootstrap_css()that could be used by shinyswatch in the future, although it's not strictly required. The approach used byinclude_bootstrap_css()is quite similar to the one taken here, except that its stated goal is to replace only the CSS and not the entire Bootstrap bundle. That function will also provide additional runtime checks to make sure that Shiny's Bootstrap is compatible.In a future PR, I'll come back to shinyswatch and explore using the new function. In the mean time, the approach in this PR should work for both current and the expected future implementation in Shiny. As long as this PR doesn't break shinyswatch, I'd like to merge this so that work in Shiny can be tested.
New naming of shinyswatch dependency
The core shinyswatch deps are now named
shinyswatch-jsandshinyswatch-css. This way, if multiple themes are added, only onebootstrap.bundle.min.jsand onebootswatch.min.cssare ever loaded.Re-worked theme picker
The theme picker now uses a separate HTMLDependency to load all of the themes at once. New JavaScript switches themes by replacing the initial theme with a new
<link>. We actually add the new CSS and then remove the previous CSS with a slight delay, resulting in a smooth transition between themes.Kapture.2024-04-05.at.09.30.38.mp4