Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
How to automatically remove access permanently to shiny app after fixed time once they are logged in?

I have shinyapps.io standard plan, i give access to users though their email id. https://www.shinyapps.io/

Requirements:- I want to write code that the access is removed permanently after certain time once they are successfully logged in.

App should be stopped for only one particular user whose time limit is over and should not affect other logged in users in anyways (who have logged in recently and their time limit is not over).

What I have done:-

I asked this question on rstudio community. https://community.rstudio.com/t/how-to-automatically-remove-access-permanently-to-shiny-app-after-fixed-time-once-they-are-logged-in/134564/2

Based on suggestion, i tried the below code,

library(shiny)
library(htmltools)

ui <- fluidPage(
  h1('My Shiny app'),
  p('You will be disconnected after 5 seconds...'),
  tags$script(HTML(
    "
      document.addEventListener('DOMContentLoaded', (event) => {
        setTimeout(() => {Shiny.onInputChange('disconnect', true)}, 5000)
      } )
    "
  ))
)

server <- function(input, output, session) {
  observeEvent(input$disconnect, {
    if (input$disconnect) shiny::stopApp()
  })
}

shinyApp(ui, server)

Outcome:-

While the app closes when testing on Rstudio, but it just disconnect on browser, and if you refresh the website, you get access again.

Is there anyway that once login is successful first time, after certain time access is removed permanently?

Can anyone modify the code or show any example/link where it has been discussed earlier?

Will appreciate it so much.

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You will need to set some cookies. This approach is by no means fool proof (user can delete cookies), but in the following toy example you will notice that for the first time when you launch the app, it will log out after 5 seconds and in consequent runs it will log out immediately.

library(shiny)
library(htmltools)

ui <- fluidPage(
   tags$head(
      tags$script(
         src = paste0(
            "https://cdn.jsdelivr.net/npm/js-cookie@rc/",
            "dist/js.cookie.min.js"
         )
      )
   ),
   h1('My Shiny app'),
   p('In your first run you will be disconnected after 5 seconds...'),
   p('...while in consecutive runs you will be logged out immediately'),
   tags$script(HTML(
      "
      $(document).on('shiny:connected', (event) => {
        if (Cookies.get('logon')) {
           Shiny.onInputChange('disconnect', true);
        } else {
           setTimeout(() => {Shiny.onInputChange('disconnect', true)}, 5000);
           Cookies.set('logon', true);
        }
      } )
    "
   ))
)

server <- function(input, output, session) {
   observeEvent(input$disconnect, {
      if (input$disconnect) shiny::stopApp()
   })
}

shinyApp(ui, server)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!