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

How to run golem app as background job by invoking run_dev()? #1145

Open
jzadra opened this issue Jun 18, 2024 · 3 comments
Open

How to run golem app as background job by invoking run_dev()? #1145

jzadra opened this issue Jun 18, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@jzadra
Copy link

jzadra commented Jun 18, 2024

I prefer to have my shiny apps run as a background job so that the console remains free. Is there a way to change the way run_dev() works in order to make that the default?

In addition, I think that this would have the added benefit of ensuring that the app runs in a clean environment, without having to clean the interactive environment, allowing the console environment to stay as is. I use golem::detach_all_attached() and rm(list=ls(all.names = TRUE)) in run_dev.R to ensure that the app runs in a clean environment each time. However, this can be slightly sub-optimal for development because if I want to do some testing/debugging in the console without having to specify the package with package::function(), it means that every time I run the app, I have to reload any libraries (usually library(tidyverse)) to avoid this during interactive coding.

Note - sorry, I didn't mean to label this as a bug or assign @ColinFay, and I"m not able to delete it to post as a feature request.

@jzadra jzadra added the bug Something isn't working label Jun 18, 2024
@VincentGuyader
Copy link
Member

Hi

Your need seems to be a Job for "shiny autoreload" see #263, what do you think about this @ColinFay ?

@ColinFay
Copy link
Member

Hey,

As far as I understand it, this is not really the autoreload feature that we are looking for here — autoreload doesn't free the console (AFAIK).

The following code should do what you're looking for:

proc <- processx::process$new(
  "Rscript", 
  c("-e", "golem::run_dev()"), 
  # This is the part of the code that will allow the subprocess
  # to print to the current R console
  stdout = "", 
  stderr = ""
)
# When you want to stop and restart
proc$kill()

Let me know if that answers your request.

@ColinFay ColinFay added enhancement New feature or request and removed bug Something isn't working labels Jun 21, 2024
@jzadra
Copy link
Author

jzadra commented Jul 2, 2024

This does most of what I'm looking for (for others reading, it doesn't appear in "Background Jobs", but it does keep your console available.

The only issue with this method it that even though golem::run_dev() eventually invokes golem::run_app(), which in a normal console start will open the shiny app. However using the method @ColinFay provided, it does not open the app. The localhost and port are displayed in the console upon launch, but then it's necessary to copy/paste that into a browser.

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

No branches or pull requests

3 participants