그래서 future
패키지를 사용하여 몇 가지 예제를 보았습니다. 코드가 앱이 닫힌 경우에도 별도의 세션 (클러스터)에서 실행됩니다. 다음 단계는 프로세스가 아직 실행 중이거나 완료되었는지 확인하는 방법을 파악하는 것입니다. 어떤 아이디어?
library(future)
cl <- parallel::makeCluster(2L)
plan(cluster, workers = cl)
server <- function(input, output) {
observeEvent(input$run, {
iteration <- as.numeric(input$iteration)
path <- input$path
future::future({
writeLog <- function(n, path) {
file.remove(path)
for (i in 1:n) {
cat("#", i, "-", as.character(Sys.time()), "\n", file = path, append = TRUE)
Sys.sleep(1)
}
}
writeLog(iteration, path)
}, globals = c("iteration", "path"))
})
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
tags$div("This app writes to file in cluster which means it is computed in parallel to this session.
It will execute even when app is closed.")
, br()
, shiny::textInput("path", "Path to log file", value = "/src/dev/export_performance/future.log")
, shiny::textInput("iteration", "Iteration number", value = 60)
),
mainPanel(
br()
, actionButton("run", "Run future")
)
)
)
shinyApp(ui = ui, server = server)
출처
2017-09-17 18:44:12
Taz
'mcparallel'이 효과가 있습니까? https://stat.ethz.ch/R-manual/R-devel/library/parallel/html/mcparallel.html –
@Roman Luštrik는, 그래,하지만'제가 종료 후에도 작동 독립적 인 세션을 만들 수 mcparallel' 않습니다 앱? – Taz
유닉스 머신에 액세스 할 수 없기 때문에 실제로 테스트 할 수는 없습니다. –