terminate learnr tutorial after given time

I've made some learnr tutorials which my statistics students interact with through an RStudio workbench server.

The issue is that student don't always remember to stop the tutorial, so their instance of RStudio is running on the server even when they close their browser. This uses memory resources.

I'd like to have the tutorial turn off automatically after say 30 minutes. How can I do that?

Thanks in Advance.

You can try this concept:

library(shiny)
time_out_value <- 5 # cant be in the app more than x seconds

ui <- fluidPage(
  verbatimTextOutput("txt")
)

server <- function(input, output, session) {
  initial_time <- Sys.time( )
  tdiff <- function(){
    round(Sys.time()-initial_time,0)
  }
  clocktime <- reactivePoll(1000,session,
                            checkFunc = tdiff,
                            valueFunc = tdiff)
  
  observe({
    ct <- clocktime()
    if(ct>time_out_value){
      stopApp()
    }
  })
  
  output$txt <- renderPrint({
    cat("Time in App: ", req(clocktime()))
  })
}

shinyApp(ui, server)

@nirgrahamuk, Thanks for your post, this is an interesting idea...

I'm new at programming. I pasted your code into a script and got that to run, and I mostly understand what it does.

How can I implement this in a specific learnr .rmd?

I've tried pasting your example to the setup chunk of a learnr .rmd but the tutorial does not stop. Please excuse my ignorance, I appreciate any guidance.