You can do the following:
shiny_running = function () {
frames = sys.frames()
calls = lapply(sys.calls(), `[[`, 1)
call_name = function (call)
if (is.function(call)) '<closure>' else deparse(call)
call_names = vapply(calls, call_name, character(1))
target_call = grep('^runApp$', call_names)
if (length(target_call) == 0)
return(FALSE)
target_frame = frames[[target_call]]
namespace_frame = parent.env(target_frame)
isNamespace(namespace_frame) && environmentName(namespace_frame) == 'shiny'
}
shiny_running() , , Shiny.
, , () , Shiny - , .
"modules" .
, . Shiny/RMarkdown, YAML: , runtime .
shiny_running = function ()
identical(rmarkdown::metadata$runtime, 'shiny')