【发布时间】:2018-03-24 23:04:35
【问题描述】:
我每天通过 cron 作业为我闪亮的应用程序更新我的 RData 文件。 但是,闪亮的应用程序大部分时间不会选择更新并继续显示旧 RData 文件中的旧数据。
这是最小的可重现示例。从我的桌面执行 data_processing.R 时它工作正常。但是,当它在 Rshiny 服务器上完成时,闪亮的应用程序不会读取更新的日期和时间戳。
data_processing.R
rm(list=ls())
df <- iris
data_update_date_time <- Sys.time()
save.image("working_dataset.RData", compress = TRUE)
server.R
load("working_dataset.RData")
function(input, output, session) {
# Combine the selected variables into a new data frame
selectedData <- reactive({
df[, c(input$xcol, input$ycol)]
})
clusters <- reactive({
kmeans(selectedData(), input$clusters)
})
output$plot1 <- renderPlot({
palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
par(mar = c(5.1, 4.1, 0, 1))
plot(selectedData(),
col = clusters()$cluster,
pch = 20, cex = 3)
points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
})
## Data update date and time stamp
output$update_date_time <- renderPrint(data_update_date_time)
}
ui.R
pageWithSidebar(
headerPanel('Iris k-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable', names(iris),
selected=names(iris)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9),
br(),
h4("Date update date time"),
textOutput("update_date_time")
),
mainPanel(
plotOutput('plot1')
)
)
感谢您抽出宝贵时间。
【问题讨论】:
-
如果你把
load("working_dataset.RData")放在你的服务器函数中,图像应该在每个新会话中重新加载。服务器函数之外的变量的生命周期几乎是不可预测的 AFAIK。 -
感谢您的好建议。