5

Is there a session id/ session key assigned to each shiny session (if deployed on a shiny server)? If yes, how do I access the info? I have read the documentation here and looked online, however, could not really find the answer to my questions.

Any info would be appreciated. Many thanks!

mizzlosis
  • 515
  • 1
  • 4
  • 17

2 Answers2

13

I was looking into it and session$token worked for me

Best

Enrique Gurdiel
  • 131
  • 1
  • 4
1

Just create your own. For example:

session.id <- reactive({ as.character(floor(runif(1)*1e20)) })

When session.id() is used for the first time, it will randomly generate a value, but since it does not contain any reactives it will never be invalidated and so the value will stay the same for the rest of the session.

dk.
  • 2,030
  • 1
  • 22
  • 22
  • brilliant @dk, sometimes simple solutions are the best. – Lazarus Thurston Feb 20 '23 at 12:51
  • however will there be any situation where two shiny apps would have the same token (represented by `session$token`)? e.g. can there be an anomolous situation if the second shiny app uses the first app memory due to same thread launch? In that case the `session$token` would come handy. – Lazarus Thurston Feb 20 '23 at 12:54