When you’re running a Shiny app from a source file, like app.R
in RStudio, you can choose to run the app in the Viewer Pane, a new Window, or in an External browser window.
This works well for typical Shiny apps in app.R
or {global,ui,server}.R
, but if you’re building a Shiny app inside an R package — and if you are, then definitely check out ThinkR’s golem package — then that little Run App button won’t be available to choose where to run your Shiny apps.
The Shiny runApp() help documentation mentions the global option shiny.launch.browser
but this helpful StackOverflow answer provided a helpful hint as to how to actually pick the Viewer, Window or External location for newly launched Shiny apps.
The following options only work in RStudio, and definitely in RStudio 1.2 (I’m running 1.2.1511
). If you want to set these options globally in your ~/.Rprofile
, then I’d recommend adding a conditional guard to check that RStudio is running first.
if (
# Make sure that {rstudioapi} is available
requireNamespace("rstudioapi", quietly = TRUE) &&
# Returns TRUE if RStudio is running
::hasFun("viewer")
rstudioapi
) {options(shiny.launch.browser = your_choice_here)
}
RStudio shiny.launch.browser
Options
Run in Viewer
options(shiny.launch.browser = .rs.invokeShinyPaneViewer)
Run in Window
options(shiny.launch.browser = .rs.invokeShinyWindowViewer)
Run in External Browser
options(shiny.launch.browser = .rs.invokeShinyWindowExternal)