0

I have a shiny app running inside a shinyproxy, and I want to be able to sign out users from inside the shiny app.

Following this: Login Screen For My Shiny App Does Not Time Out, this: Time out session in R Shiny, and this: https://support.openanalytics.eu/t/logout-from-inside-app/1769, I've added a timeout to my code to trigger the log out. Here is a dummy example:

library(shiny)
library(shinyjs)
library(shinydashboard)

timeoutSeconds <- 5
inactivity <- sprintf("function idleTimer() {
  var t = setTimeout(logout, %s);
  window.onmousemove = resetTimer; // catches mouse movements
  window.onmousedown = resetTimer; // catches mouse movements
  window.onclick = resetTimer;     // catches mouse clicks
  window.onscroll = resetTimer;    // catches scrolling
  window.onkeypress = resetTimer;  //catches keyboard actions

  function logout() {
   Shiny.setInputValue('timeOut', '%ss')
  }

  function resetTimer() {
   clearTimeout(t);
   t = setTimeout(logout, %s);  // time is in milliseconds (1000 is 1 second)
  }
 }
 idleTimer();", timeoutSeconds*1000, timeoutSeconds, timeoutSeconds*1000
)

userlogOut <- "Shiny.addCustomMessageHandler('log_out', function(message) {window.location = '/logout';});"

ui <- dashboardPage(
  header = dashboardHeader(title = "Test"),
  sidebar = dashboardSidebar(tags$head(tags$script(HTML(userlogOut)))),
  body = dashboardBody(tags$script(inactivity))
)

server <- function(input, output, session) {
  observeEvent(input$timeOut, { 
    session$sendCustomMessage(type = "log_out", message = "message");
    stopApp()
  })
}

shinyApp(ui, server)

The problem is that instead of login out it sends me to the login page while I'm still logged in:

enter image description here

I've also tried to close the browser using:

userlogOut <- "Shiny.addCustomMessageHandler('log_out', function(m) {window.close();});"

Even though it works when I try it in local, it doesn't work inside the shinyproxy (it only greys out the app, but doesn't close the window).

Any suggestions?

Iria Roca
  • 161
  • 5

0 Answers0