Skip to content

Add Shiny background jobs - #5909

Merged
jmcphers merged 17 commits into
masterfrom
feature/shiny-background-job
Dec 23, 2019
Merged

jmcphers merged 17 commits into
masterfrom
feature/shiny-background-job

Conversation

@jmcphers

Copy link
Copy Markdown
Member

This change makes it possible to run Shiny applications as background jobs. This is useful for a number of reasons:

  • It unblocks the R console so that you can interact with R while Shiny is running, without using multiple copies of the IDE.
  • It runs the Shiny application in a clean R session, aiding reproducibility, and more closely simulating the environment in which the application will run when published to RStudio Connect or shinyapps.io.
  • It makes it possible to run multiple Shiny applications at once (a utility of dubious usefulness, but a utility nonetheless!)

Background mode is toggled via a new switch on the Run App menu. When the switch is set to Background Job, the Run App button launches a background job instead of sending a command to the R console.

image

A significant portion of this change is refactoring. Shiny jobs are a lot like R script jobs, so instead of building a parallel infrastructure for them, I created a more generic async R job manager and base class, from which Shiny and R Script jobs both inherit.

Closes #5190.

{
// typically the only way Shiny applications exit is by being stopped, so don't treat that
// as a failure
setJobState(job_, jobs::JobState::JobSucceeded);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably related to my above comment, but why not mark as cancelled?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aesthetics, mostly. Typically a Shiny process runs until you abort it. That means that as you run-edit-rerun an app, you will wind up with a big pile of aborted jobs. Having a big red Cancelled on every one of those jobs doesn't look nice (even though they technically were, indeed, cancelled) so we give them a nicer Succeeded treatment here.

- clean up whitespace
- use canceled state if known
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run Shiny applications or Plumber APIs as background jobs

2 participants