r - 测量 Shiny 内部的执行速度

标签 r shiny execution-time

我正在开发一个 Shiny 的应用程序。

我对计算执行某些代码块(例如 ggplot 等)所需的时间很感兴趣。

出于某种原因,使用通常的时钟方法似乎在响应式(Reactive)调用中不起作用,例如:

output$R1_C1 <- renderPlot({

beginning <- Sys.time()

<lots of code here> 

end <- Sys.time()
print(end - beginning)

R提示并给我

Error in (structure(function (input, output)  : 
  object 'beginning' not found

有没有人找到一种成功的方法来在 Shiny 的响应式调用中计时执行速度?

最佳答案

这适用于我的系统:

library(shiny)
runApp(list(
  ui = bootstrapPage(
    numericInput('n', 'Number of obs', 100),
    plotOutput('plot')
  ),
  server = function(input, output) {
    output$plot <- renderPlot({
      beginning <- Sys.time()
      h <- hist(runif(input$n)) 
      end <- Sys.time()
      print(end - beginning)
      h
    })
  }
))

关于r - 测量 Shiny 内部的执行速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27664411/

相关文章:

r - 如何删除R中仅包含缺失值的行?

仅当超过 5 个连续的重复项时,才从向量中删除连续的重复项

r - 如何将 Shiny 中生成的 react 图传递给 Rmarkdown 以生成动态报告

gcc - 如何测量处理器周期中的 x86 和 x86-64 汇编命令执行时间?

python - R Markdown : How can I make RStudio display Python plots inline instead of in new window?

r - 如何从R中的字符串中检索某些字符?

sql - R Shiny SQL Server 查询

javascript - 为什么 Shiny 的 dateInput() 会导致键盘出现在手机中?

php - 获取 PHP 中最后一个查询的实际(绝对)执行时间(不包括网络延迟等)

PHP:一次性将 10.000 行插入 mysql 性能