Just put the code inside the observeEvent() for the button
library(shiny)
ui <- basicPage(
actionButton("submit", "Submit"),
textOutput("text")
)
server <- function(input, output, session) {
observeEvent(input$submit, {
t1 <- Sys.time()
# long script goes here
Sys.sleep(2)
t2 <- Sys.time()
output$text <- renderText({
paste("The long script took", round(t2 - t1, 2), "seconds to complete")
})
})
}
shinyApp(ui, server)