Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda