Skip to content
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

If in runtime:shiny doc, restore state when shiny app stops (not when the document is knitted) #87

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion R/thematic.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,19 @@ thematic_rmd <- function(bg = "auto", fg = "auto", accent = "auto",
)
document_hook <- knitr::knit_hooks$get("document")
knitr::knit_hooks$set(document = function(x) {
thematic_set_theme(old_theme)
if (is_shiny_runtime()) {
shiny::onStop(function() thematic_set_theme(old_theme))
} else {
thematic_set_theme(old_theme)
}
document_hook(x)
})
invisible(old_theme)
}

is_shiny_runtime <- function() {
isTRUE(grepl("^shiny", knitr::opts_knit$get("rmarkdown.runtime")))
}

#' Tools for getting and restoring global state
#'
Expand Down