2014-12-27 99 views
1

我正在开发一个Shiny应用程序。测量Shiny内部的执行速度

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

因为这似乎是使用通常的计时方法没有反应电话中工作,例如某些原因:

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 

有没有人发现了一个成功的在闪亮的被动呼叫中执行速度的方法?

回答

3

这个作品在我的系统上:

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 
    }) 
    } 
))