我正在开发一个 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/