我使用的googleAuthR
包在闪亮,我想提醒用户,如果他们没有登录,我也想保存用户的谷歌id,如果他们已经成功登录。但是sign_ins()是反应性的使用者,我不能这样做。有什么建议吗?
library(shiny)
library(googleAuthR)
library(shinyWidgets)
options(googleAuthR.webapp.client_id = "**********************")
ui <- fluidPage(
titlePanel("Sample Google Sign-In"),
sidebarLayout(
sidebarPanel(
googleSignInUI("demo")
),
mainPanel(
with(tags, dl(dt("Name"), dd(textOutput("g_name")),
dt("Email"), dd(textOutput("g_email")),
dt("Image"), dd(uiOutput("g_image")) ))
)
)
)
server <- function(input, output, session) {
sign_ins <- shiny::callModule(googleSignIn, "demo")
output$g_name = renderText({ sign_ins()$name })
output$g_email = renderText({ sign_ins()$email })
output$g_image = renderUI({ img(src=sign_ins()$image) })
if(is.null(sign_ins())){
shinyWidgets::show_alert(title = "not log in",
type = NULL,
btn_labels = "Ok")
else{
write.csv(sign_ins(),"file.csv")
}
}
}
# Run the application
shinyApp(ui = ui, server = server)
发布于 2022-01-06 10:07:33
我不熟悉googleAuthR
,但是R中的每个google产品都很可能有"*_has_token“特性来验证会话中是否有活动凭证。我已经检查了googleAuthR
包,我认为您可以使用googleAuthR::gar_has_token()
。所以而不是
if(is.null(sign_ins())) {...}
您可以使用
if(googleAuthR::gar_has_token() == FALSE){...}
检查是否有活动凭据,并执行您的任务。希望这有帮助
https://stackoverflow.com/questions/70604869
复制相似问题