Calling one shiny app from within my shiny app

Hello all,

I have one unusual question to ask. It would be so great If I get the solution.

I have made the shiny application and I want to call one other shiny application(Facto shiny already made for PCA) into my existed shiny code.
I have been trying to do that with the source() but I am getting error Can't call runApp() from within runApp(). If your application code contains runApp(), please remove it.
Of course, the other shiny(fact shiny) app has UI.R and server. R of its own.
Has anyone tried this before ?? Is it possible to do so?
Please let me know, this will be very helpful for me.

1 Like

You can't run one Shiny application within another Shiny application when running the application locally (running from R directly instead of from a hosted platform like Shiny Server, Connect, or shinyapps.io). If you are deploying your application on a server, however, you can use an iframe that points to the other application.

1 Like

Thanks winston for you response.
However, I am deploying the shiny app in a docker (making a package of shiny app and then after installation of docker , I will put my package into docker)
Well I read about 'Modularizing shiny app code' , In the section of packaging module . Seems like it is possible to do but somehow I am not able to catch how?
Kindly let me know In my case as i am making a package of shiny will it be possible to do so?

As I was thinking will it possible to make a function of this Factoshiny shiny app(which i want within my shiny app) and then call into my shiny app code?

Shiny modules share some similarities with full Shiny applications, but they are not themselves Shiny applications. The previous solution I mentioned -- an iframe in an app -- is the way to go. A hosting platform like Shiny Server is the most straightforward way to do what you want, which is to run multiple Shiny applications simultaneously.

Hi Winston, is there an example that I can check for the shiny server for running different apps?

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