Open romunov opened 5 years ago
The googleSingIn
module loads the Google SignIn JavaScript on this line:
This needs to occur before any call to its JS library. The module shouldn't be wrapped in another renderUI
, instead put the changes within the googleSignInUI
function
If that's the case, I can't really bring data from server to UI to dynamically generate name on the button (e.g. "Logout (Roman)"). Or am I missing something?
You can pass in the argument to the UI module, so something like:
googleSignInUI <- function(id, logout_message = "Sign Out"){
ns <- shiny::NS(id)
if(getOption("googleAuthR.webapp.client_id") == ""){
stop("You need to set options('googleAuthR.webapp.client_id' = 'your.client.id') - see website: https://code.markedmondson.me/googleAuthR/articles/google-authentication-types.html#googlesignin-module-example", call. = FALSE)
}
shiny::tagList(
shiny::tags$head(
shiny::tags$meta(name="google-signin-scope", content="profile email"),
shiny::tags$meta(name="google-signin-client_id", content=getOption("googleAuthR.webapp.client_id")),
shiny::HTML('<script src="https://apis.google.com/js/platform.js?onload=init"></script>')
),
shiny::div(id=ns("signin"), class="g-signin2", "data-onsuccess"="onSignIn"),
shiny::tags$button(id = ns("signout"), logout_message, onclick="signOut();", class="btn-danger"),
load_js_template("js/signin-top.js",
ns("signin"), ns("signout") ,ns("g_id"), ns("g_name"), ns("g_image"), ns("g_email")),
load_js_template("js/signin-bottom.js",
ns("g_id"), ns("g_name"), ns("g_image"), ns("g_email"))
)
}
And then in the ui.R it will be called via:
ui <- fluidPage(
titlePanel("reproducible example"),
sidebarLayout(
sidebarPanel(
googleSignInUI("google_signin", logout_message="My Sign Out")
),
mainPanel()
)
)
I'm not sure how server side variables can be passed into Shiny UI modules, would need to look that up.
What goes wrong
When rendering
googleSignInUI
throughrenderUI
, a warning is issued. Blocker is disabled.Steps to reproduce the problem
Expected output
If you switch to "regular" rendering only in the UI part (commented), there is no warning. I believe the warning comes from signin-bottom.js. Unfortunately I'm not JS-savvy and I'm not sure how to catch this borderline case.
Actual output
(no output to consider)
Session Info