我有一个闪亮的应用程序/服务器,我强制运行20秒,然后我在浏览器上运行进度条。但是,如果我要刷新浏览器,那么在应用程序运行完毕之前,浏览器不会刷新。刷新浏览器时有没有办法让应用程序终止?
这是我的申请。应用程序接受任何文件,然后单击ActionButton时,应用程序运行20秒。同时,进度条将显示在页面顶部。
在server.R
中library(shiny)
shinyServer(function(input, output, session) {
# Wait for start_proc to be clicked and then download the data frame
get_download <- eventReactive(input$start_proc,
{
withProgress(message = "Processing", {
n = 20
for (i in 1:n){
incProgress(1/n, detail = paste("", sep = ""))
Sys.sleep(1)
}
})
# Create the data frame
df = data.frame(c(1,1,1),c(2,2,2))
output$data_file <- downloadHandler(
filename = function() {
paste('probabilities-', Sys.Date(), '.txt', sep='')
}
,
content = function(file1) {
write.table(df, file = file1)
}
)
})
# Observe when file is uploaded
observe({
inFile <- input$upload
if (is.null(inFile))
return(NULL)
get_download()
})
})
在ui.R
library(shiny)
shinyUI(fixedPage(
fileInput("upload", ""),
actionButton("start_proc", h5("Compute Probability\n")),
downloadButton("data_file"),
helpText("Download will be available once the processing is completed.")
))