-
-
Notifications
You must be signed in to change notification settings - Fork 996
Add shiny::bootstrapLib() as a dependency inside html_document_base()'s pre-processor #2049
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
Changes from all commits
55973ef
841f9f0
1851825
de1edf7
5e6a928
1886417
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,16 +134,21 @@ run <- function(file = "index.Rmd", dir = dirname(file), default_file = NULL, | |
| yaml_front <- if (length(target_file)) yaml_front_matter(target_file) | ||
| runtime <- yaml_front$runtime | ||
| theme <- render_args$output_options$theme | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cpsievert as I am going through shiny prerendered code base to understand better how it works, I am just wondering what this line is used for ? It does not seem to be used now with the PR changes. Do you recall the aim of catching a special handling when |
||
| # 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)) | ||
cderv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| theme <- format$options$theme | ||
| set_current_theme(resolve_theme(format$options$theme)) | ||
| } | ||
|
|
||
| # run using the requested mode | ||
| if (is_shiny_prerendered(runtime)) { | ||
|
|
||
| # get the pre-rendered shiny app | ||
| app <- shiny_prerendered_app(target_file, render_args = render_args, theme = theme) | ||
| app <- shiny_prerendered_app(target_file, render_args = render_args) | ||
| } else { | ||
|
|
||
| # add rmd_resources handler on start | ||
|
|
@@ -158,7 +163,7 @@ run <- function(file = "index.Rmd", dir = dirname(file), default_file = NULL, | |
| # combine the user-supplied list of Shiny arguments with our own and start | ||
| # the Shiny server; handle requests for the root (/) and any R markdown files | ||
| # within | ||
| app <- shiny::shinyApp(ui = rmarkdown_shiny_ui(dir, default_file, theme), | ||
| app <- shiny::shinyApp(ui = rmarkdown_shiny_ui(dir, default_file), | ||
| uiPattern = "^/$|^/index\\.html?$|^(/.*\\.[Rr][Mm][Dd])$", | ||
| onStart = onStart, | ||
| server = rmarkdown_shiny_server( | ||
|
|
@@ -317,7 +322,7 @@ rmarkdown_shiny_server <- function(dir, file, auto_reload, render_args) { | |
| } | ||
|
|
||
| # create the Shiny UI function | ||
| rmarkdown_shiny_ui <- function(dir, file, theme) { | ||
| rmarkdown_shiny_ui <- function(dir, file) { | ||
| function(req) { | ||
| # map requests to / to requests for the default--index.Rmd, or another if | ||
| # specified | ||
|
|
@@ -339,8 +344,7 @@ rmarkdown_shiny_ui <- function(dir, file, theme) { | |
| tags$div( | ||
| tags$head( | ||
| tags$script(src = "rmd_resources/rmd_loader.js"), | ||
| tags$link(href = "rmd_resources/rmd_loader.css", rel = "stylesheet"), | ||
| shiny_bootstrap_lib(theme) | ||
| tags$link(href = "rmd_resources/rmd_loader.css", rel = "stylesheet") | ||
| ), | ||
|
|
||
| # Shiny shows the outer conditionalPanel as long as the document hasn't | ||
|
|
@@ -586,3 +590,10 @@ read_shiny_deps <- function(files_dir) { | |
| list() | ||
| } | ||
| } | ||
|
|
||
|
|
||
| # shiny:::setCurrentTheme() was added in 1.6 (we may export in next version) | ||
| set_current_theme <- function(theme) { | ||
| set_theme <- asNamespace("shiny")$setCurrentTheme | ||
| if (is.function(set_theme)) set_theme(theme) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.