shinymanager icon indicating copy to clipboard operation
shinymanager copied to clipboard

Using shinymanager along with session$OnSessionEnded() to close the app.

Open SanthoshManikantan opened this issue 2 years ago • 3 comments

I have an application which uses the shinymanager library for user login. I want to use the session$onSessionEnded() to close my app once the browser is closed. As suggested by @ismirsehregal here shinymanager with onsessioneneded() the workaround is working fine for the login but if we logout or going to administrator mode (while using db) the app is getting stopped. Could you please provide a workaround for this. samplecode

`library(shiny) library(shinyWidgets) library(shinythemes) library(shinymanager)

credentials <- data.frame( user = c("admin", "shinymanager"), # mandatory password = c("admin", "12345"), # mandatory start = c("2022-04-15"), # optinal (all others) expire = c(NA, "2026-12-31"), admin = c(TRUE, TRUE), comment = "Simple and secure authentification mechanism for single ‘Shiny’ applications.", stringsAsFactors = FALSE )

ui <- fluidPage( sliderInput("n", "Number of observations", 2, 1000, 500), plotOutput("plot") )

ui <- secure_app(ui)

server <- function(input, output, session) { res_auth <- secure_server( check_credentials = check_credentials(credentials) )

session$onSessionEnded(function() { print(paste("Session", session$token, "ended")) if(!is.null(isolate({res_auth$user}))){ stopApp() } })

observe({ # Re-execute this reactive expression after 1000 milliseconds invalidateLater(1000, session) print(paste("The value of input$n is", isolate(input$n))) }) output$plot <- renderPlot({ # Re-execute this reactive expression after 2000 milliseconds invalidateLater(2000) hist(rnorm(isolate(input$n))) }) }

shinyApp(ui, server)`

SanthoshManikantan avatar Jan 10 '23 06:01 SanthoshManikantan

I've encountered the same issue and hope to find a solution!

SEvisual avatar Mar 04 '24 14:03 SEvisual

Why do you need to call stopApp() ? stopApp() is useful in local to free the R session but has no interest afaik on a server

pvictor avatar Mar 07 '24 16:03 pvictor

such as using shinymanager with DesktopDeployR(A framework for deploying self-contained R-based applications to the desktop), session$onSessionEnded(function() {stopApp()}) IMPORTANT! this is needed to terminate the R process when the shiny app session ends. Otherwise, you end up with a zombie process

SEvisual avatar Mar 08 '24 03:03 SEvisual