diff --git a/R/html_dependencies.R b/R/html_dependencies.R
index 99280d6463..8670b9b84b 100644
--- a/R/html_dependencies.R
+++ b/R/html_dependencies.R
@@ -126,8 +126,7 @@ as_bs_theme <- function(theme) {
}
is_bs_theme <- function(theme) {
- is_available("bslib") &&
- bslib::is_bs_theme(theme)
+ is_available("bslib") && bslib::is_bs_theme(theme)
}
theme_version <- function(theme) {
diff --git a/R/shiny.R b/R/shiny.R
index b666963e0e..28c5bc681a 100644
--- a/R/shiny.R
+++ b/R/shiny.R
@@ -133,14 +133,16 @@ run <- function(file = "index.Rmd", dir = dirname(file), default_file = NULL,
target_file <- file %||% file.path(dir, default_file)
yaml_front <- if (length(target_file)) yaml_front_matter(target_file)
runtime <- yaml_front$runtime
- theme <- render_args$output_options$theme
# Let shiny::getCurrentTheme() know about the yaml's theme, so
# things like `bslib::bs_themer()` can work with prerendered documents.
# Also note that we add the actual shiny::bootstrapLib() dependency
# inside the document's pre-processing hook so the 'last' version of
# the theme wins out
if (length(target_file)) {
- format <- output_format_from_yaml_front_matter(read_utf8(target_file))
+ format <- output_format_from_yaml_front_matter(
+ input_lines = read_utf8(target_file),
+ output_options = render_args$output_options
+ )
set_current_theme(resolve_theme(format$options$theme))
}
diff --git a/tests/testthat/test-shiny.R b/tests/testthat/test-shiny.R
index c4afa14910..37dc1147a4 100644
--- a/tests/testthat/test-shiny.R
+++ b/tests/testthat/test-shiny.R
@@ -18,13 +18,16 @@ test_that("file.path.ci returns correctly no matter the case", {
})
-test_that("set_current_theme() informs shiny::getCurrentTheme()", {
+test_that("set_current_theme() informs shiny::getCurrentTheme() only with bslib theme", {
+ skip_if_not(packageVersion("shiny") >= 1.6)
expect_null(shiny::getCurrentTheme())
- theme <- bslib::bs_theme()
- set_current_theme(theme)
+ set_current_theme(theme <- bslib::bs_theme())
expect_equal(theme, shiny::getCurrentTheme())
set_current_theme(NULL)
expect_null(shiny::getCurrentTheme())
+ set_current_theme(theme <- "cerulean")
+ expect_equal(theme, shiny::getCurrentTheme())
+ set_current_theme(NULL)
})
test_that("html_prerendered is a full document template to use as UI for shiny", {