title: How to time reactive function in Shiny app in r
body: <p>I have a function that I would like to time, and then display on the UI how much time it took to execute that function. How can I get the execution time of that function re-actively? I have tried to put the variable in the reactive function, around the function, etc. I just want to time how long it takes for the reactive function to run and then display it. I am trying not to use additional packages.</p>
  
  <pre><code>library(shiny)
  # Define UI for application that draws a histogram
  ui &lt;- fluidPage(
  
    sidebarPanel(
      # User Input Text  Box
      textInput(inputId = "userText",
            label = "",
            placeholder = "Type in a partial sentence here..."),
      verbatimTextOutput(outputId = "textInput", placeholder = TRUE),
  
      # Show amount of execution time
      verbatimTextOutput(outputId = "timer", placeholder = TRUE)  
  ))
  
  server &lt;- function(input, output) {
  
    # Declare Timer variables
    startTime &lt;- Sys.time()
    endTime &lt;- Sys.time()
  
    # Some function to time: Trivial Paste Function
    textToDisplay &lt;- reactive({
      req(input$userText)
      startTime &lt;- Sys.time()
      textToDisplay &lt;- paste("This is the user input text: ", input$userText)
      endTime &lt;- Sys.time()
      return(textToDisplay)
    })
  
    # Display pasted text
    output$textInput &lt;- renderText({
      req(input$userText)
      textToDisplay()
  
    })
  
    # Display execution time
    output$timer &lt;- renderText({
      req(input$userText)
      paste0("Executed in: ",((endTime - startTime)*1000)," milliseconds")
    })
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>The code above does not update or show the proper time difference correctly.</p>