无法使用 Azure Active Directory 对 R-Shiny App 进行身份验证

问题描述 投票:0回答:0

我正在开发一个托管在 R-Shiny 平台上的 R-Shiny 应用程序。在此过程中,我需要对应用程序进行身份验证,以便我可以从 OneDrive 下载某些文件并使用它们在 R-Shiny 上托管应用程序。

因此,我目前正在使用 Azure Active Directory 设置继续并在应用程序上提供身份验证。 Azure 刷新令牌应该能够继续并处理该身份验证过程,因为它能够自动刷新。

我一直在关注此特定教程中的模板代码,以便将 Microsoft365R 与 R-Shiny 结合使用:https://cran.r-project.org/web/packages/Microsoft365R/vignettes/shiny.html#:~:text=这个%20vignette%20描述了%20how%20to%20incorporate%20Microsoft365R%20and,token%20Pass%20%20token%20to%20%20Microsoft365R%20functions.

目前,问题是每当我插入用于检索天蓝色令牌的代码时,我的应用程序都不会按预期加载预期的图。

截至目前,我已参考提供的模板继续并实施了以下代码。

library(AzureAuth)
library(AzureGraph)
library(Microsoft365R)
library(shiny)
library(httr)

tenant <- 'exampletenantID'

app <- 'exampleappID'

redirect <- " https://flashdrought.shinyapps.io/Flash_tool/"
port <- httr::parse_url(redirect)$port
options(shiny.port = if (is.null(port))
  443
  else
    as.numeric(port))

pwd <- Sys.getenv(client_passcode, "")
if (pwd == "")
  pwd <- NULL

resource <- c("https://graph.microsoft.com/.default", "openid")

DateRun = seq(as.Date("2022-01-01"), as.Date(Sys.Date() - 2), by = 1)


ui <- fluidPage(# Application title
  titlePanel(
    title = div(
      id = "dummy",
      img(
        height = 75,
        width = 75,
        src = "FLASHlogo.png",
        #style="position:absolute;top:330px;right:35px;z-index:1000;"
      ),
      "Global Flash Drought Stress Assessment"
    )
  ),
  
  plotOutput(outputId = "distPlot"),
  hr(),
  fluidRow(column(
    3,
    h4("Select a date"),
    selectInput("Date", "(yyyy-mm-dd)", choices = DateRun),
    actionButton("goButton", "Update")
  )))


server <- function(input, output, session) {
  library(terra)
  library(RColorBrewer)
  library(spData)
  library(terra)
  library(tmap)
  
  output$distPlot <- renderPlot({
    dataSelect = format(as.Date(input$Date), "%Y%m%d")
    
    opts <- parseQueryString(isolate(session$clientData$redirect))
    if (is.null(opts$code))
      return()
    
    tokenGet <-
      get_azure_token(
        c(
          "https://graph.microsoft.com/User.Read.All",
          "https://graph.microsoft.com/User.ReadWrite.All",
          "https://graph.microsoft.com/Directory.ReadWrite.All",
          "offline_access"
        ),
        tenant,
        app,
        password = pwd,
        auth_type = "authorization_code",
        authorize_args = list(redirect_uri = redirect),
        version = 2,
        auth_code = opts$code,
        aad_host = currentHost
      )
    
    dataSelect = format(as.Date(input$Date), "%Y%m%d")
    
    od <- get_personal_onedrive()
    od$list_items()
    od$list_files()
    od$download_file(paste("Public/FDSI/fdsiRas-", dataSelect, ".tif", sep =
                             ""),
                     overwrite = TRUE)
    FDSIselect = rast(paste("fdsiRas-", dataSelect, ".tif", sep = ""))
    
    cols <- colorRampPalette(
      brewer.pal(11, 'RdYlBu'),
      space = 'Lab',
      interpolate = 'spline',
      bias = 1
    )
    mypal = cols(6)
    #~~~~~~~~~~~~~~~~
    #tmap_mode("plot")
    myMap = tm_shape(FDSIselect) +
      tm_raster(
        title = "Flash Drought Stress Index",
        palette = rev(mypal),
        style = "fixed",
        breaks = c(0, 0.2, 0.4, 0.5, 0.6, 0.71, 1),
      ) +
      tm_layout(legend.position = c("left", "bottom")) +
      tm_grid(alpha = 0.2) +
      tm_xlab("Longitude", size = 1.2) +
      tm_ylab("Latitude", size = 1.2) +
      tm_layout(
        inner.margins = 0,
        legend.text.size = 1.1,
        legend.title.size = 1.2
      ) +
      tm_shape(world) +
      tm_sf(alpha = 0.25)
    
    print(myMap)
    file.remove(paste("fdsiRas-", dataSelect, ".tif", sep = ""))
    
  })
  
}

这是预期的输出。 Expected Output

但是,当我运行上面的代码时,我只是得到一个空白屏幕。任何建议和指导将不胜感激谢谢!

r azure shiny gis raster
© www.soinside.com 2019 - 2024. All rights reserved.