RStudio Cloud: Running web apps on localhost

Hey there,

I'm teaching a class in R this week and in a bit of a pickle because of this whole COVID-19 thing - I have to transition all my lecturing to online. I thought I'd take the opportunity to try out RStudio Cloud for some live coding.

Unfortunately, there seems to be a problem in how I'm launching localhost web apps in RStudio cloud.

Here is a link to my project: Posit Cloud (it is public).

When I run the same code locally, I serve up the app (Rscript app.R), and can then open the app in either a browser, or in the viewer using rstudioapi::viewer("http://localhost:8050")

Here is a screenshot of it working (locally) --> can't add two screenshots... darn.

And here's what happens when I try to run it in RStudio Cloud:

It's stuck on the loading screen. When I right click in the viewer and click open frame in new window, the new URL is: https://firas-moosvi.rstudio.cloud/3a97e29ffc204637b4884ab0047ebb09/p/359db0e0/?viewer_pane=1&capabilities=1&host=https%3A%2F%2Ffiras-moosvi.rstudio.cloud

But it's still stuck on the loading screen. The only thing I could thing to do was use the Javascript console to look at errors. It seems the app cannot find the resources it needs at this address :

[Error] Failed to load resource: the server responded with a status of 404 () (dash_renderer.v1_2_2m1584421283.min.js, line 0)

This https://forum.posit.co/t/launching-localhost-web-apps-in-rstudio-cloud/21078/12 topic was very helpful in getting me started at some things to try, but eventually I think our issues diverged.

Appreciate any tips you might have!

Hello,

I think the issue here involves an interaction between the package and rstudio cloud and it looks like the URLs to resources are not being generated correctly. If you run the following you get a URL to where the dashboard is running,

rstudioapi::translateLocalUrl(url="[https://localhost:8050](https://localhost:8050/)", absolute = TRUE)

If you follow that URL then all of the javascript links are malformed because they need to be prefixed with the URL to the dashboard. I believe setting the below seems to fix the issue on my end,

prefix <- rstudioapi::translateLocalUrl(url="https://localhost:8050", absolute = TRUE)
app <- Dash$new(requests_pathname_prefix = prefix)

Sean

1 Like

Thanks Sean! That looks like it SHOULD solve it, but I get this error:

Error: RStudio not running

This seems to be related to rstudioapi.

Try using the source button, or sourcing app.R in the console, rather than running via the terminal.

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