att / rcloud.shiny

Shiny support for RCloud
Other
4 stars 12 forks source link

shutdown #26

Closed gordonwoodhull closed 6 years ago

gordonwoodhull commented 6 years ago

Currently we've disabled all shutdown code in our override of shiny:::runApp, because we need the function to return control, not block until done.

Can we put all of the on.exit() functionality that's currently commented out into a separate shutdownApp function, that we call explicitly when the page is closed?

gordonwoodhull commented 6 years ago

I think this is the only major obstacle to contributing our changes back to Shiny. It's also something people want in itself, for example "I'm trying to use session$onSessionEnded to push final updates to a DB".

gordonwoodhull commented 6 years ago

FWIW this SO answer provides a test

            users_data <- data.frame(START = Sys.time())
            session$onSessionEnded(function() {
                users_data$END <- Sys.time()
                # Write a file in your working directory
                write.table(x = users_data, file = file.path("/tmp/users_data.txt"),
                append = TRUE, row.names = FALSE, col.names = FALSE, sep = "\t")
            })

Only difference is using getwd() for the path didn't work for me, since the temporary directory gets deleted when the session closes. This tripped me up for a minute or two.

gordonwoodhull commented 6 years ago

Implemented in #31