Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app doesn't work in posit cloud #79

Closed
calderonsamuel opened this issue Apr 24, 2023 · 6 comments
Closed

app doesn't work in posit cloud #79

calderonsamuel opened this issue Apr 24, 2023 · 6 comments

Comments

@calderonsamuel
Copy link
Collaborator

There seems to be an issue in open_bg_shinyapp(). The translated URL sometimes works fine and sometimes opens an external browser with an unexpected URL that leads nowhere. This was tried multiple times in different blank posit cloud projects.

@idavydov
Copy link
Contributor

idavydov commented May 2, 2023

I have issues with rstudio server. I often get connection refused. Maybe it's related to the time needed to load the shiny app?

What about adding this code after the run_app_as_bg_job() instead of if (.Platform$OS.type == "unix") Sys.sleep(1.5)?

  # wait for the app to start
  start_time <- as.numeric(Sys.time())
  repeat {
    r <- tryCatch(
      httr::GET(glue::glue("http://{host}:{port}/")),
      error = \(e) NULL
    )
    if (
      as.numeric(Sys.time()) - start_time > 10 ||
        (!is.null(r) && httr::status_code(r) < 300)
    ) {
      break
    }
    Sys.sleep(0.2)
  }

That seems to solve the issue for rstudio server for me.

@calderonsamuel
Copy link
Collaborator Author

You spotted my very unrealiable bug fix for linux 🥲 . Your code looks like a much better aproach in handling the wait for the app starting time. However, the bug I found is different and it seems related to the URL translation. Allow me to explain it better.

In a new empty project when you have only installed {gptstudio} and setup your API KEY, the addin should open the app in the background and show it in the Viewer pane. The viewer needs a URL to show, and that URL must:

  1. have a format accepted for the viewer pane (this error)
  2. have content (otherwise you get the connection refused error).

When 1 is not respected the URL is opened in the system's browser. Here is how it goes with the chatgpt app:

gptstudio.bug.in.posit.cloud.mp4

The addin is still running in the background, but it is not possible to get a valid translated URL, even if you run the following code while the app runs in the jobs panel:

url <- "http://127.0.0.1:<port>"
rstudioapi::viewer(rstudioapi::translateLocalUrl(url))

However, if you manually close the app and restart the R session, you can create a fake app wrapping the relevant app modules. This is to get the Run App button in Rstudio. With this, you can choose to run the app in the Viewer pane. After that it is possible to inspect the URL with the format that the Viewer pane accepts.

Video.sin.titulo.3.mp4

I believe this is the format that rstudioapi::translateLocalUrl() should be returning but it doesn't for some reason. If this is a bug in {rstudioapi} we should warn the users. If this is a bug from this repo we should fix it. I'm also not sure in how to create an automated test for this.

@calderonsamuel
Copy link
Collaborator Author

There seems to be an unexpected manual fix for this. I don't know why this works but it does. After installation you need to relaunch the project. If you do this the addin runs with no problems. This is not the same as restarting the R session, I've tried that and it still fails if you don't relaunch the project.

You can see it in action here (in Youtube because it was too long for Github):

gptstudio - Posit cloud relaunch fix

Maybe {gptstudio} should warn about this on install?

@JamesHWade
Copy link
Collaborator

Your experience is similar to one I've seen on Posit Workbench. This might be an artifact of working on RStudio server environments in general. Best approach might be to get this issue in from of the team at Posit support Cloud and Workbench.

@calderonsamuel
Copy link
Collaborator Author

I'm thinking on closing this since downloading from CRAN works after restarting the R session (no longer requires to Relaunch project). @JamesHWade Can you test on Posit Workbench to confirm? If not, we still can close this until someone reports on Posit Workbench.

@calderonsamuel
Copy link
Collaborator Author

Closing until someone reports something similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants