Skip to content

Commit 4e9955b

Browse files
authored
Render shiny.min.css using bs_theme() (#1191)
1 parent 47ea7a5 commit 4e9955b

File tree

11 files changed

+71
-28
lines changed

11 files changed

+71
-28
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Bug fixes
1515

16+
* Shiny now compiles the Bootstrap 5-based stylesheets for component styles imported from https://github.com/rstudio/shiny. (#1191)
17+
1618
### Other changes
1719

1820
* Closed #1178: Removed run-time dependency on asgiref. (#1183)

scripts/htmlDependencies.R

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env Rscript
22

3+
if (requireNamespace("cli", quietly = TRUE)) {
4+
message <- function(..., .envir = parent.frame()) {
5+
cli::cli_progress_step(paste0(...), .envir = .envir)
6+
}
7+
}
8+
39
message("Checking for node / npm")
410
if (Sys.which("npm")[["npm"]] == "") {
511
stop("Please install node / npm before running script")
@@ -206,6 +212,62 @@ ignored <- lapply(woff_files, function(woff_file) {
206212
}
207213
})
208214

215+
# ------------------------------------------------------------------------------
216+
message("Render shiny.min.css with bs_theme()")
217+
with_sass_options <- withr::with_(function(x) rlang::exec(sass::sass_options_set, !!!x))
218+
219+
sass_opts_minify <- list(
220+
output_style = "compressed",
221+
source_comments = FALSE,
222+
source_map_embed = FALSE
223+
)
224+
225+
shiny_css_dep <- with_sass_options(
226+
sass_opts_minify,
227+
shiny:::shinyDependencyCSS(shiny_theme)
228+
)
229+
shiny_css_bslib <- fs::path(shiny_css_dep$src$file, shiny_css_dep$stylesheet)
230+
shiny_css_shared <- fs::path(www_shared, "shiny.min.css")
231+
writeLines(
232+
c(
233+
readLines(shiny_css_shared, n = 1), # keep header of original minified css
234+
readLines(shiny_css_bslib)
235+
),
236+
con = shiny_css_shared
237+
)
238+
239+
message("Render selectize.min.js with bs_theme()")
240+
selectize_css_dep <- with_sass_options(
241+
sass_opts_minify,
242+
shiny:::selectizeDependencyFunc(shiny_theme)
243+
)
244+
selectize_css_bslib <- fs::path(
245+
selectize_css_dep$src$file,
246+
selectize_css_dep$stylesheet
247+
)
248+
selectize_shared <- fs::path(www_shared, "selectize", "css")
249+
fs::file_delete(fs::path(selectize_shared, "selectize.bootstrap3.css"))
250+
fs::file_copy(
251+
selectize_css_bslib,
252+
fs::path(selectize_shared, "selectize.min.css"),
253+
overwrite = TRUE
254+
)
255+
256+
message("Render datepicker.min.css with bs_theme()")
257+
datepicker_css_dep <- with_sass_options(
258+
sass_opts_minify,
259+
shiny:::datePickerCSS(shiny_theme)
260+
)
261+
datepicker_css_bslib <- fs::path(
262+
datepicker_css_dep$src$file,
263+
datepicker_css_dep$stylesheet
264+
)
265+
datepicker_shared <- fs::path(www_shared, "datepicker", "css")
266+
fs::file_copy(
267+
datepicker_css_bslib,
268+
fs::path(datepicker_shared, "bootstrap-datepicker3.min.css"),
269+
overwrite = TRUE
270+
)
209271

210272
# ------------------------------------------------------------------------------
211273
message("Cleanup bootstrap bundle")

shiny/ui/_html_deps_external.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def datepicker_deps() -> HTMLDependency:
5757
name="bootstrap-datepicker",
5858
version="1.9.0",
5959
source={"package": "shiny", "subdir": "www/shared/datepicker/"},
60-
# TODO: pre-compile the Bootstrap 5 version?
6160
stylesheet={"href": "css/bootstrap-datepicker3.min.css"},
6261
script={"src": "js/bootstrap-datepicker.min.js"},
6362
# Need to enable noConflict mode. See #1346.
@@ -76,8 +75,7 @@ def selectize_deps() -> HTMLDependency:
7675
{"src": "js/selectize.min.js"},
7776
{"src": "accessibility/js/selectize-plugin-a11y.min.js"},
7877
],
79-
# TODO: pre-compile the Bootstrap 5 version?
80-
stylesheet={"href": "css/selectize.bootstrap3.css"},
78+
stylesheet={"href": "css/selectize.min.css"},
8179
)
8280

8381

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
33
"shiny_version": "Github (rstudio/shiny@6760c318184535185e5050aefe29e658e8710ef0)",
4-
"bslib_version": "Github (rstudio/bslib@13357888d018b00d8f209b84e3f627dcdc567e64)",
4+
"bslib_version": "Github (rstudio/bslib@243499ae83509ce0fe66d36488b0e20e8c227e26)",
55
"htmltools_version": "CRAN (R 4.3.1)",
66
"bootstrap_version": "5.3.1"
77
}

shiny/www/shared/bootstrap/bootstrap.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"note!": "This file is auto-generated by scripts/htmlDependencies.R",
33
"package": "bslib",
4-
"version": "Github (rstudio/bslib@13357888d018b00d8f209b84e3f627dcdc567e64)"
4+
"version": "Github (rstudio/bslib@243499ae83509ce0fe66d36488b0e20e8c227e26)"
55
}

shiny/www/shared/datepicker/css/bootstrap-datepicker3.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/shared/selectize/css/selectize.bootstrap3.css

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)