4

我想创建一个闪亮的应用程序来分析谷歌表格中的一些数据。它将部署在服务器上。该表仅适用于公司内部的用户,因此我需要实施身份验证(api 密钥方法在这里不起作用),正如我googleAuthR现在在互联网上阅读的那样,这是唯一的选择(参见https://github.com/ r-lib/gargle/issues/14 )

首先,这是不使用默认身份验证方法的应用程序:

library(googleAuthR)
library(googlesheets4)
library(shinyjs)

ui <- shinyUI(navbarPage(title = 'sample_app',
                         tabPanel(
                                  useShinyjs(),
                                  tableOutput('test')
                         )
))

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

  read_my_sheet <- function() {
    sheets_auth(scopes = "https://www.googleapis.com/auth/spreadsheets.readonly",
                cache = FALSE, use_oob = FALSE)
    read_sheet("<MY_SHEET_ID>")
  }

  output$test <- renderTable({
    read_my_sheet()
  })
}

shinyApp(ui, server)

如您所见,该应用程序要求我在启动应用程序后立即通过 Tidyverse API 包应用程序进行身份验证。我想要的是首先加载应用程序,通过单击使用googleAuth模块的按钮开始身份验证过程,获取令牌并将其传递给sheets_auth因此不需要 Tidyverse 身份验证。我的尝试:

options("googleAuthR.scopes.selected" = c("https://www.googleapis.com/auth/spreadsheets.readonly"))
options("googleAuthR.webapp.client_id" = "<MY_CLIENT_ID>")
options("googleAuthR.webapp.client_secret" = "<MY_CLIENT_SECRET>")
options(shiny.port = 8787)

library(googleAuthR)
library(googlesheets4)
library(shinyjs)


ui <- shinyUI(navbarPage(title = 'sample_app',
                         tabPanel(
                           useShinyjs(),
                           googleAuthUI('gauth_login'),
                           tableOutput('test')
                         )
))

server <- function(input, output, session) {
  access_token <- callModule(googleAuth, "gauth_login")

  read_my_sheet <- function() {
    fil <- access_token()
    sheets_auth(token = fil, scopes = "https://www.googleapis.com/auth/spreadsheets.readonly",
                cache = FALSE, use_oob = FALSE)
    read_sheet("<MY_SHEET_ID>")
  }

  output$test <- renderTable({
    read_my_sheet()
  })
}

shinyApp(ui, server)

不幸的是,当启动应用程序时,第一个出现的又是一个要求 Tidyverse 进行身份验证的窗口。如何关闭它?我只想使用我的客户端进行身份验证。

4

0 回答 0