2014-12-27 32 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 
    }) 
    } 
))