Start Shiny Application (Non-Blocking) — startApp
R/runapp.R
Description
Starts a Shiny application in non-blocking mode, returning a
ShinyAppHandle immediately while the app runs in the background.
The later event loop services the app, so the R console remains
available for interaction.
Arguments
- appDir
The application to run. Should be one of the following:
A directory containing
server.R, plus, eitherui.Ror awwwdirectory that contains the fileindex.html.A directory containing
app.R.An
.Rfile containing a Shiny application, ending with an expression that produces a Shiny app object.A list with
uiandservercomponents.A Shiny app object created by
shinyApp().
- port
The TCP port that the application should listen on. If the
portis not specified, and theshiny.portoption is set (withoptions(shiny.port = XX)), then that port will be used. Otherwise, use a random port between 3000:8000, excluding ports that are blocked by Google Chrome for being considered unsafe: 3659, 4045, 5060, 5061, 6000, 6566, 6665:6669 and 6697. Up to twenty random ports will be tried.- launch.browser
If true, the system's default web browser will be launched automatically after the app is started. Defaults to true in interactive sessions only. The value of this parameter can also be a function to call with the application's URL.
- host
The IPv4 address that the application should listen on. Defaults to the
shiny.hostoption, if set, or"127.0.0.1"if not. See Details.- workerId
Can generally be ignored. Exists to help some editions of Shiny Server Pro route requests to the correct process.
- quiet
Should Shiny status messages be shown? Defaults to FALSE.
- display.mode
The mode in which to display the application. If set to the value
"showcase", shows application code and metadata from aDESCRIPTIONfile in the application directory alongside the application. If set to"normal", displays the application normally. Defaults to"auto", which displays the application in the mode given in itsDESCRIPTIONfile, if any.- test.mode
Should the application be launched in test mode? This is only used for recording or running automated tests. Defaults to the
shiny.testmodeoption, or FALSE if the option is not set.
Value
A ShinyAppHandle object with methods stop(), status(),
url(), and result(). The status() method returns "running",
"success", or "error". The result() method throws an error if called
while running, or re-throws the error if the app stopped with an error.
Details
To stop a non-blocking app from the R console, call handle$stop()
on the returned ShinyAppHandle. Despite the similar name, stopApp()
is not the counterpart of startApp() — it is for use from inside
app code (e.g. server functions, observers, or the onStart hook),
where it sets a return value that is later surfaced via
handle$result().
Auto-replacement
If another Shiny app is already running in this session when startApp()
is called, the running app is stopped before the new one starts.
Stopping happens up front, so if the new app then fails to start, no app
will be running. You can always call handle$stop() on the existing
handle first if you would rather manage the transition yourself.
See also
runApp() for blocking mode.