Calling one shiny app from within my shiny app

There is no direct way to launch a shiny app from within another shiny app. Calling runApp() inside a shiny app will result in this error,

Warning: Error in shiny::runApp: Can't callrunApp()from withinrunApp(). If your application code containsrunApp(), please remove it.

But, with RStudio 1.2 there is a workaround. We can store runApp() of second app in an R script and execute this script as a separate R Studio Job. This will start the second shiny app in a new session without stopping the first one.

Code:

script.R

shiny::runApp(path_to_app, launch.browser = TRUE, port = 875)

ui.R

actionButton("launch_app", "Launch second Shiny App")

server.R

    observeEvent(input$launch_app, {
            rstudioapi::jobRunScript(path = path_to_script)
        })

If this is for a package, store the script in inst/ and use system.file() to build paths.

4 Likes