unable to fetch session data

...
we have appended a valrialble and its dynamic value in our ui5 like (shinyurl?user_id = emp_id) where user_id is variable and emp_id is its dynamic value which changes for each user who log in to our product. Now, i want to fetch this variable value in R Studio. How to do it?

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")

Tried all the ways but not getting user_id value in txt file. Only @ sys.time() is captured there.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.