If you want runApp() to return a value, I believe the only nice way to do that is to call stopApp() with the return value when a certain 'done' action happens:
library(shiny)
runApp(list(
ui = fluidPage(
"Append '?user_id=abc' to url then close",
actionButton("done", "Done")
),
server = function(input, output, session) {
observeEvent(input$done, {
query <- parseQueryString(session$clientData$url_search)
stopApp(query[["user_id"]])
})
}
))
If you can't rely on users to click done, but you're somehow in an interactive environment, you could keep track of the user in a 'global variable'
user_id <- NULL
runApp(list(
ui = fluidPage("Append '?user_id=abc' to url then close"),
server = function(input, output, session) {
observe({
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[["user_id"]])) {
user_id <<- query[["user_id"]]
}
})
}
), launch.browser = TRUE)
user_id
You probably want to save the user id to disk though, along with the Sys.time()
runApp(list(
ui = fluidPage("Append '?user_id=abc' to url then close"),
server = function(input, output, session) {
observe({
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[["user_id"]])) {
cat(query[["user_id"]], "@", Sys.time(), "\n", file = "user_ids.txt", append = TRUE)
}
})
}
), launch.browser = TRUE)
You could then access those ids with readLines("user_ids.txt")