我有一个闪亮的应用程序,它使用相当长的功能,可定期将更新打印到控制台。我想将这些对象的renderPrint()渲染到一个闪亮的窗口,以便用户知道工作仍在进行中。我已经能够使该系统按预期在macOS High Sierra 10.13.6和Shinyapps.io上运行。
但是,当尝试在我的Mint Linux或Ubuntu 18.04 Shiny Server上运行此命令时,日志记录不会实时更新,而是在函数调用完成后立即打印所有记录。我的想法是这是一个文件锁定的操作系统问题,因为多个进程正在访问一个临时文件,但是我的理解是Shinyapps.io使用Ubuntu,所以我不知道是否存在允许更改的权限设置应用程序可以正常工作。
我对Unix文件权限和文件锁定一无所知,因此,如果有人有任何建议,将不胜感激,谢谢!
edit:经过一番寻找之后,看来这仅适用于plan(multicore)
下面是确认可在macOS High Sierra 10.13.6和Shinyapps.io上运行的最低工作示例:
ui.R
library(shiny)
fluidPage(
mainPanel(
actionButton("run", "Run"),
div(id="outDiv", verbatimTextOutput("consoletext")),
tags$head(tags$style("#outDiv{overflow-y:scroll; max-height: 100px;}")),
tags$script(
'
Shiny.addCustomMessageHandler("scrollCallback",
function(color) {
var objDiv = document.getElementById("outDiv");
objDiv.scrollTop = objDiv.scrollHeight;
}
);'
)
)
)
server.R
library(shiny)
library(future)
library(promises)
library(rprintf)
plan(multiprocess)
library(Rcpp)
sourceCpp("test.cpp")
tmpfile <- tempfile()
function(input, output, session) {
observeEvent(input$run, {
sink(tmpfile, type=c("output", "message"), append=FALSE)
future({
test()
}) %...>%
(function(x) {
print("Complete")
})
sink()
})
log <- reactiveFileReader(50, session=session, tmpfile, read.delim, sep="\n")
output$consoletext <- renderPrint({
try(
suppressWarnings(print(log())), silent=TRUE)
session$sendCustomMessage(type = "scrollCallback", 1)
})
}
test.cpp
#include <Rcpp.h>
#include <unistd.h>
using namespace Rcpp;
// [[Rcpp::export]]
void test()
{
for (int i=0; i<5; i++) {
Rprintf("Step: %i\n", i);
usleep(3000000);
}
}
sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Rcpp_0.12.17 rprintf_0.2.1 promises_1.0.1 future_1.8.1 shiny_1.1.0
loaded via a namespace (and not attached):
[1] codetools_0.2-15 listenv_0.7.0 digest_0.6.15 later_0.7.2 mime_0.5 R6_2.2.2
[7] xtable_1.8-2 jsonlite_1.5 magrittr_1.5 rlang_0.2.1 stringi_1.2.2 tools_3.4.4
[13] parallel_3.4.4 httpuv_1.4.3 rsconnect_0.8.8 compiler_3.4.4 globals_0.11.0 htmltools_0.3.6