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

Cannot open browser from callr process #177

Closed
wlandau opened this issue Dec 18, 2020 · 3 comments
Closed

Cannot open browser from callr process #177

wlandau opened this issue Dec 18, 2020 · 3 comments

Comments

@wlandau
Copy link

wlandau commented Dec 18, 2020

callr::r(function() browseURL("https://github.com")) does not open a browser window even though browseURL("https://github.com") does. This is relevant for non-blocking Shiny apps, e.g. shiny::runApp(launch.browser = TRUE).

@wlandau
Copy link
Author

wlandau commented Dec 18, 2020

Motivation: ropensci/targets#248. My workaround is to launch the app in r_bg() and then call browseURL() from the parent process, but it is not perfect because the browser usually launches before the app can initialize. I am not sure how shiny::runApp() avoids this problem.

@gaborcsardi
Copy link
Member

That is intentional:

callr/R/rcmd.R

Line 106 in 5cf65b9

R_BROWSER = "false",

For the early use cases we did not want subprocesses to open browsers. It is somewhat different nowadays, but probably too late to change.

Workaround:

callr::r(
  function() browseURL("https://github.com"), 
  env = c(R_BROWSER = Sys.getenv("R_BROWSER"))
)

@wlandau
Copy link
Author

wlandau commented Dec 18, 2020

Thanks, @gaborcsardi. That's totally fair.

I actually figured out a different workaround that does not require R_BROWER:

  • Child: pass the host and port to options in shinyApp().
  • Parent: ping the port until it is up, then call browseURL().

Currently using this in targets::tar_watch() and proffer::serve_pprof().

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

No branches or pull requests

2 participants