From 2a4bf8c4e005d05fd96e1d847b2ed7aae124b221 Mon Sep 17 00:00:00 2001 From: Bruceshark <33870780+bruceyyu@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:10:13 +0800 Subject: [PATCH] fix: global var & stopApp (#34) --- R/gwalkr_kernel.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/gwalkr_kernel.R b/R/gwalkr_kernel.R index ea8264b..8e5daeb 100644 --- a/R/gwalkr_kernel.R +++ b/R/gwalkr_kernel.R @@ -1,3 +1,5 @@ +utils::globalVariables(c(".rs.invokeShinyPaneViewer")) + convert_timestamps_in_df <- function(df) { for (colname in colnames(df)) { if (inherits(df[[colname]], "POSIXt")) { @@ -9,7 +11,7 @@ convert_timestamps_in_df <- function(df) { gwalkr_kernel <- function(data, lang, dark, rawFields, visConfig, toolbarExclude) { cat("GWalkR kernel mode initialized...\n") - cat("Note: The console is unavailable while running a Shiny app. You can stop the app to use the console, or press Ctrl + C to terminate.\n") + cat("Note: The console is unavailable while running a Shiny app. You can stop the app to use the console.\n") filter_func <- function(data, req) { query <- parseQueryString(req$QUERY_STRING) @@ -29,6 +31,12 @@ gwalkr_kernel <- function(data, lang, dark, rawFields, visConfig, toolbarExclude ) } + app_options <- if (exists(".rs.invokeShinyPaneViewer")) { + c(launch.browser = .rs.invokeShinyPaneViewer) + } else { + list() + } + app <- shinyApp( ui = fluidPage( shinycssloaders::withSpinner( @@ -63,18 +71,19 @@ gwalkr_kernel <- function(data, lang, dark, rawFields, visConfig, toolbarExclude name = 'gwalkr', x, package = 'GWalkR', - width='100%', - height='100%' + width = '100%', + height = '100%' ) }) session$onSessionEnded(function() { cat("GwalkR closed") duckdb_unregister_con() + stopApp() }) }, - options=c(launch.browser = .rs.invokeShinyPaneViewer) + options = app_options ) if (interactive()) app -} \ No newline at end of file +}