r – ShinyApp谷歌登录

我有一个shinyapp,我想为使用谷歌登录登录应用程序的成员启用某些功能.我无法使用GoogleAuthR软件包在我的应用中实施Google登录和身份验证过程.有没有人有一个样本ShinyApp的例子,它允许观众通过谷歌或任何其他社交论坛授权登录

欣赏带代码的演示.

PS:我无意运行谷歌数据的统计数据,但我只想废除为我的应用程序创建登录模块的麻烦,让谷歌登录处理麻烦

谢谢
SD

最佳答案 在
readme中有一个例子,你可以看到作为
Shiny app here工作

如果您打算仅用于登录目的,请查看使用googleAuthR构建的GoogleID软件包,并牢记这一点.

示例代码如下:

## in global.R
library(googleAuthR)
library(shiny)

options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/urlshortener")
options(googleAnalyticsR.webapp.client_id = "YOUR_PROJECT_KEY")
options(googleAnalyticsR.webapp.client_secret = "YOUR_CLIENT_SECRET")

shorten_url <- function(url){

  body = list(
    longUrl = url
  )

  f <- gar_api_generator("https://www.googleapis.com/urlshortener/v1/url",
                         "POST",
                         data_parse_function = function(x) x$id)

  f(the_body = body)

}

## server.R
source("global.R")

server <- function(input, output, session){

  ## Create access token and render login button
  access_token <- callModule(googleAuth, "loginButton")

  short_url_output <- eventReactive(input$submit, {
    ## wrap existing function with_shiny
    ## pass the reactive token in shiny_access_token
    ## pass other named arguments
    with_shiny(f = shorten_url, 
               shiny_access_token = access_token(),
               url=input$url)

  })

  output$short_url <- renderText({

    short_url_output()

  })
}

## ui.R
ui <- fluidPage(
  googleAuthUI("loginButton"),
  textInput("url", "Enter URL"),
  actionButton("submit", "Shorten URL"),
  textOutput("short_url")
)


### If the above global.R, server.R and ui.R files are in folder "test" like so:
## /home
##    |->/test/
##            /global.R
##            /ui.R
##            /server.R
##
## Port 1221 has been set in your Google Project options as the port to listen to
## as explained in authentication setup section
## run below in /home directory
shiny::runApp("./test/", launch.browser=T, port=1221)
点赞