小编BBO*_*BBO的帖子

如何不等待 R 中的承诺评估

我想在闪亮的应用程序中的单独 R 会话中执行一个非常昂贵的函数(在下面的示例中称为“never_ending_calc”)。我已经准备好了下面的代码,它工作正常,但我的父 R 会话等待 promise 对象的结果,这使用了大量资源。如果您在下面的测试应用程序运行时检查任务管理器,您将看到父 R 会话使用一个最大容量的 CPU 线程,而只是简单地等待 promise 对象的结果。

如何以不使用父 R 会话资源的方式评估承诺?(如果我松开这两个会话之间的连接也可以。)

我尝试了以下(它们都不起作用):

  • 使用不同的“计划”
  • 从函数“never_ending_calc”的第一行发送自定义消息(如警告),以某种方式停止父会话以等待承诺对象

这是示例:

library(shiny)
library(future)
library(promises)
library(future.callr)

never_ending_calc <- function(){
  K = 1
  for (i in 1:20){
    K = K + i
    Sys.sleep(5)
  }
  return(K)
}

ui <- fluidPage(

  # App title ----
  titlePanel("Test app"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel ----
    sidebarPanel(

      # action button to start the long test calculation ----
      actionButton(inputId = "start_test", …
Run Code Online (Sandbox Code Playgroud)

future r promise shiny

5
推荐指数
0
解决办法
75
查看次数

标签 统计

future ×1

promise ×1

r ×1

shiny ×1