From c0f101ba64a686730d49f5aa6cd69b0830aea187 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 4 Feb 2021 11:14:18 -0600 Subject: [PATCH] Close #86: If in runtime:shiny doc, restore state when shiny app stops (not when the document is knitted) --- 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 #'