From ef8ae83327ba8994ec70c1d4a6cbce2888f4ec25 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Fri, 5 Feb 2021 16:30:20 -0600 Subject: [PATCH] Close #86: If in runtime:shiny doc, restore state when shiny app stops (not when the document is knitted) (#87) --- R/thematic.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/R/thematic.R b/R/thematic.R index 33c3b70b..94d6c6d5 100644 --- a/R/thematic.R +++ b/R/thematic.R @@ -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 #'