You can listen for all kinds of events in Shiny applications, either from the window or from individual elements, and run JavaScript code when they occur. For example, you can listen for when Shiny makes the initial connection with the client, and you can listen for when Shiny is busy or idle. You can listen for when an input changes, or an output recalculates. For a full list, see the documentation at shiny.rstudio.com/articles/js-events.html. As an example, we're going to make a very simple program that takes a long time to draw a graph and gives you a little alert box when it is finished. The program is so simple that we will use the single-file app.R format. Here, it is reproduced in its entirety:
ui <- fluidPage(
titlePanel("JavaScript Events"),
sidebarLayout(
sidebarPanel(
actionButton("redraw", "...