我无法将闪亮的应用程序部署到闪亮的服务器上 .
基本上,我有一个每天早上更新的CSV,我希望服务器上闪亮的应用程序检查是否每五分钟刷新一次并反应性地编辑数据并显示下面的图表 .
这个数据修改( create_issue_spotter_data
)在R中需要相对较长的时间,所以我还有一个稍微粗略的方法来确保在新会话开始时不会发生这种数据刷新:我有一个 start
变量来检查它是否等于1 . 如果是,则递增以便下次 chat_file()
更新时,将调用 create_issue_spotter_data
函数 . 我的做法很糟糕 .
当这个应用程序在本地运行时,它正是我想要的 . 但是,它不适用于闪亮的服务器 . 代码发布如下:
write.csv(mtcars, 'mtcars.csv')
create_issue_spotter_data = function(df) {
df$new_column = 0
df = df[df$mpg < 20, ]
return(df)
}
ui <- fluidPage(
fluidRow(align = "center", downloadButton("download_btn")),
fluidRow(align = "center", plotOutput("distPlot"))
)
server <- function(input, output) {
start <- 1
file <- reactiveFileReader(
intervalMillis = 1000 * 60 * 5,
session = NULL,
filePath = 'mtcars.csv',
readFunc = readr::read_csv
)
this_df = eventReactive(file(), {
if (start != 1) {
print(paste("Now updating the data. Date:", Sys.time()))
saved_df <<- create_issue_spotter_data(file())
df <- saved_df
} else {
start <<- start + 1
print(paste("Everything's good at", Sys.time()))
df <- saved_df
}
df
})
output$download_btn <- downloadHandler(
filename = paste0(paste("Issue", "Spotter", gsub("-", "_", Sys.Date()), sep = "_"), ".pdf"),
content = function(file) {
pdf(file)
p = build_cluster_viz(this_df(), download = TRUE)
print(p)
dev.off()
}, contentType = "pdf")
output$distPlot <- renderPlot({
plot(this_df()$mpg, this_df()$disp)
})
}