RStudio Server: How to determine port hash for a shiny app?

When running any shiny app in RStudio Server, if I run the app in the viewer pane

Screen Shot 2020-03-02 at 4.54.12 PM

and then click "Show in new window", I get a new browser tab whose URL is forwarded by RStudio Server to the host and port of the running shiny app. For example, if I run

> shiny::runApp('test')

Listening on

I can go to The 626f2650 path appears to be some sort of hash mapping back to

Is it possible determine what this hash is programmatically? For example, if I specify a new port

shiny::runApp('test', port = 33333)

how can I determine what xxxxxxxx is here?

After some investigation of the RStudio source code, I found where the port mapping is done.

Unfortunately, the mapping is a function of a browser cookie that RStudio Server sets and I doubt it is possible to retrieve this value from the R session running on the server.

Can you elaborate on why you need that particular URL?

I'll admit it is an odd reason... I only used shiny::runApp as an example because it is familiar. In actuality, I want to be lazy and leverage RStudio's port mapping to access another web service in another browser tab without opening more ports on the host machine. The other web service being glances in this particular case (I'm looking to monitor resource consumption).

I was thinking of printing the port-mapped link from some code in, so it would only be known to authenticated RStudio Server sessions.

I ended up using the rstudioapi package to open the service in the Viewer. I can then pop it out into another tab manually.


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