Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SanthoshManikantan opened this issue Jan 10, 2023 · 3 comments

Comments

@SanthoshManikantan
Copy link

SanthoshManikantan commented Jan 10, 2023

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)`

@SEvisual
Copy link

SEvisual commented Mar 4, 2024

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

@pvictor
Copy link
Collaborator

pvictor commented Mar 7, 2024

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

@SEvisual
Copy link

SEvisual commented Mar 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

3 participants