I am trying to call another shinny app when i push an actionbutton in a very simple shiny app. The other application is in a folder called benefits with ui.R and server.R files, but when i click the button nothing happens. Is it possible what i am trying to do??
Cheers.
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("RunnApp"),
mainPanel(
actionButton("goButton", "Go!")
)
))
library(shiny)
shinyServer(function(input, output) {
ntext <- eventReactive(input$goButton, {
runApp("benefits")
})
})
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 call `runApp()` from within `runApp()`. If your application code contains `runApp()`, 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With