From 106a643472398d634326ce5fd17121bfc0ce24b5 Mon Sep 17 00:00:00 2001 From: timelyportfolio Date: Wed, 7 Mar 2018 06:12:32 -0600 Subject: [PATCH] stop Shiny when session ends https://github.com/r-spatial/mapedit/issues/71 --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ R/edit.R | 11 +++++++++++ R/query.R | 11 +++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 204b7ad..26f7c70 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,8 +2,8 @@ Package: mapedit Title: Interactive Editing of Spatial Data in R Description: Suite of interactive functions and helpers for selecting and editing geospatial data. -Version: 0.4.1 -Date: 2018-03-01 +Version: 0.4.2 +Date: 2018-03-07 Authors@R: c( person("Tim", "Appelhans", role = c("aut", "cre"), email = "tim.appelhans@gmail.com"), person("Kenton", "Russell", role = c("aut")) diff --git a/NEWS.md b/NEWS.md index 274c1c2..8b365f5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## mapedit 0.4.2 (develop) + +* stopApp when session ended to handle when a user closes a browser tab or window when using `viewer = browserViewer(browser = getOption("browser"))` + ## mapedit 0.4.1 ### Bug Fix diff --git a/R/edit.R b/R/edit.R index 82feb50..44ecfab 100644 --- a/R/edit.R +++ b/R/edit.R @@ -107,6 +107,17 @@ $(document).on('shiny:disconnected', function() { ) }) + # if browser viewer and user closes tab/window + # then Shiny does not stop so we will stopApp + # when a session ends. This works fine unless a user might + # have two sessions open. Closing one will also close the + # other. + session$onSessionEnded(function() { + # should this be a cancel where we send NULL + # or a done where we send crud() + shiny::stopApp(isolate(crud())) + }) + shiny::observeEvent(input$cancel, { shiny::stopApp (NULL) }) } diff --git a/R/query.R b/R/query.R index 341e028..ba78625 100644 --- a/R/query.R +++ b/R/query.R @@ -89,6 +89,17 @@ $(document).on('shiny:disconnected', function() { }) shiny::observeEvent(input$cancel, { shiny::stopApp (NULL) }) + + # if browser viewer and user closes tab/window + # then Shiny does not stop so we will stopApp + # when a session ends. This works fine unless a user might + # have two sessions open. Closing one will also close the + # other. + session$onSessionEnded(function() { + # should this be a cancel where we send NULL + # or a done where we send crud() + shiny::stopApp(isolate(selections())) + }) }