Skip to content

Run Shiny applications or Plumber APIs as background jobs #5190

Closed

Description

@jmcphers

Several enterprising users have noticed that you can use the new Jobs tab to run Shiny applications in the background, using a multi-step process:

  1. Create a host script that runs the application
  2. Run the host script as a local job in the Jobs tab
  3. Copy the URL from the script's output and open it in the Viewer (or an external browser with rstudoapi::translateLocalURL)

This is a nifty trick and popular enough that we could consider offering a gesture that embraces and simplifies this workflow, for example by having a checkbox in the Run App dropdown that says Run as Job. In this mode, the Shiny app would run as a background job in the Jobs tab, and you could continue to work as usual while interacting with the Shiny application. Of course, you wouldn't get debugging and would possibly lose other features (for example the run/reload/stop buttons have some edge cases to consider) but would be very helpful for some use cases.

Activity

  1. dracodoc commented on Oct 18, 2019

    @dracodoc

    I really like this feature and it's easy enough to implement, so I just did it here.
    shiny_job

  2. vnijs commented on Dec 3, 2019

    @vnijs

    This is very nice! Thanks for making the add-in @dracodoc.

    @jmcphers Is there a way to use this feature and still be able to communicate with Rstudio? Now it seems that rstudioapi::isAvailable() gives FALSE and rstudioapi::getSourceEditorContext() won't work when run from the app.

  3. jmcphers commented on Dec 3, 2019

    @jmcphers
    MemberAuthor

    Yup, if you use the development branch of rstudio and rstudioapi. See e.g. rstudio/rstudioapi#155

  4. jmcphers commented on Dec 6, 2019

    @jmcphers
    MemberAuthor

    One of the reasons this is going to be a little more involved than you might think is that most of the code that works with Shiny apps and Plumber APIs assumes that you can only run one at a time -- so there are a few singleton classes, and variables which track the "currently running Shiny app". An advantage of background jobs, of course, is that you can run more than one at once, but that means that we'll need to refactor a good deal of the code that handles the run state.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions