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 http://127.0.0.1:7515

I can go to https://rstudio-server.example.com/p/626f2650/. The 626f2650 path appears to be some sort of hash mapping back to http://127.0.0.1:7515.

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? https://rstudio-server.example.com/p/xxxxxxxx/

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 Rprofile.site, 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.

rstudioapi::viewer("http://localhost:33333")

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