【发布时间】:2020-12-01 17:04:49
【问题描述】:
我正在制作一个闪亮的应用程序,它应该从保管箱下载一个 .html 文件并通过htmlOutput() 在所述闪亮的应用程序中显示它。此外,我让它在 AWS EC2 t2.micro 实例上运行(所有闪亮的服务器配置都基于this article)。问题是我的应用程序可以在 localhost、shinyapps.io 上运行;但是,它不适用于我的 EC2 实例。该应用程序在 Shiny Server 上运行(在 EC2 实例内)。
这里是源代码(app.R):
library(shiny)
library(rdrop2)
library(httr)
# token <- drop_auth()
# saveRDS(token, "droptoken.rds")
# Upload droptoken to your server
# ******** WARNING ********
# Losing this file will give anyone
# complete control of your Dropbox account
# You can then revoke the rdrop2 app from your
# dropbox account and start over.
# ******** WARNING ********
# read it back with readRDS
token <- readRDS("droptoken.rds")
# Then pass the token to each drop_ function
drop_acc(dtoken = token)
ui <- fluidPage(
h1("rdrop2 practice"),
htmlOutput("viewFile")
)
server <- shinyServer(function(input, output, session) {
directoryPath <- paste0("path1/", "path2/")
fileName <- "file.html"
filePath <- paste0(directoryPath, fileName)
# Download File
filePut <-
try({
withProgress(message = "Generating File",
detail = "This may take few seconds depending of your Internet connection",
drop_download(path = filePath,
local_path = "./www",
overwrite = TRUE,
dtoken = token)
)
fileName
}, silent = TRUE)
# Show File
output$viewFile <- renderUI({
validate(
need(filePut, 'File Not Available')
)
tags$div(class="resp-container")
tags$iframe(class="resp-iframe",
seamless = "seamless",
src = filePut)
})
})
shinyApp(ui, server)
当应用在 localhost 或 shinyapps.io 上运行时,应用会执行正确的操作并在 htmlOutput('viewFile') 上显示 html 文件。同时,它不适用于 EC2 实例。我在整个互联网上搜索了一些解决方案,但我没有尝试过。
如果有人对导致此行为的原因有所了解,我将不胜感激!
注意:我注意到我的 EC2 实例在应用运行时不发送 XHR 请求(与 shinyapps.io 不同)
预期行为
我的闪亮应用(使用 rdrop2)应该在我的 Dropbox 帐户上找到一个 .html 文件,下载它,然后能够使用 htmlOutput() 显示它
实际行为
找不到文件并在try()“文件不可用”上显示错误
账户类型
Dropbox 基础版
【问题讨论】:
标签: r amazon-ec2 shiny shinyapps rdrop2