Skip to content

Commit

Permalink
Close #86: If in runtime:shiny doc, restore state when shiny app stop…
Browse files Browse the repository at this point in the history
…s (not when the document is knitted) (#87)
  • Loading branch information
cpsievert authored Feb 5, 2021
1 parent 8711d80 commit ef8ae83
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit ef8ae83

Please sign in to comment.