【发布时间】:2021-09-03 11:05:01
【问题描述】:
我正在努力实现以下目标:
- 将 Shiny 应用部署到 shinyapps.io
- 打开时,应用会连接到 Sharepoint
- 下载并打开存储在那里的 .rda 文件。该文件包含专有数据,只有拥有相关凭据的人才能访问这些数据。
这使我可以将对应用程序的访问与对数据的访问分开(仅当您拥有相关凭据时,您才能获取数据文件 - .rda)。这也意味着向 shinyapps.io 服务器上传更精简的信息集。
在 R-studio 中一切正常,因为下载操作将 .rda 粘贴到本地文件夹中,而加载操作将在那里序列化的对象带入环境。
一旦将应用程序部署到 shinyapps.io,它就会失败(可以预见):我怀疑“下载”不再有意义。 理想情况下,应该有一个“打开”操作打开 .rda,然后将相关对象带入环境。实在是找不到了。
这是在 R-Studio 中工作的代码(我显然无法分享 Sharepoint 网站的确切细节),如果能帮助找出正确的工作流程策略以便它可以在 shinyapps.io 上工作,我们将不胜感激。
library(Microsoft365R)
site <- get_sharepoint_site(site_id = "idOfTheSharepointSite")
docs <- site$get_drive()
docs$download_file("Stuff/DelSet.Rda", overwrite = T)
load("DelSet.Rda")
编辑
实际的问题不是文件本身的管理(下面的评论应该解决这个问题)。这是 Shinyapps.io 中 Sharepoint 上的认证。 这个准系统应用程序也失败了(在 R-studio 上按预期工作)。
library(shiny)
library(Microsoft365R)
site <- get_sharepoint_site(site_id = "IDofMySite")
docs <- site$get_drive()
ui <- fluidPage(h5("Hello world!"))
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
尝试下载到临时目录:
dest <- tempfile(fileext=".rda"); docs$download_file(*, dest=dest); load(dest) -
我想我明白你的建议。我稍微修改了一下(我有多个 .Rda 文件,我特别需要那个)。我做到了:
dest <- tempfile("whatever.Rda"); docs$download_file("Stuff/DelSet.Rda", dest=dest); load(dest)。它适用于 R-studio,而不适用于 shinyapps.io。我目前的猜测是,Sharepoint autentication 存在问题,这在我的 PC(我运行 R-studio 的地方)上得到了满足,但在 shinyapps.io 服务器上却没有。只是一个疯狂的猜测。 -
@HongOoi 那(上面的评论)实际上是问题所在。我将相应地编辑问题。
-
@HongOoi 是 cran.r-project.org/web/packages/AzureAuth/vignettes/shiny.html 我是否需要实现?
-
那个小插曲基本上就是你需要做的。请注意,您必须创建自己的应用注册,不能使用 Microsoft365R 的内置应用 ID(它假定您在本地计算机上运行它)。我有一个关于在 Shiny in the works 中运行 Microsoft365R 的具体小插曲
标签: r sharepoint shiny microsoft365r