Home:ALL Converter>Calling shiny app as part of a function in R

Calling shiny app as part of a function in R

Ask Time:2016-06-10T07:50:06         Author:InspectorSands

Json Formatter

The file app.R in my working directory contains a Shiny app:

shinyApp(
   ui = fluidPage(
    textInput("name", "Write your name", value = "stranger"),
    verbatimTextOutput("greeting")
  ),
  server = function(input, output) {
    output$greeting <- renderPrint({
      greeting <- paste("Hi,", input$name) 
      greeting
    })
  }
)

I want to call this app from within a function in R, then exit the app and have R execute the rest of the function. The function looks like this:

hi.app <- function() {
  library(shiny)
  shiny::runApp("app.R")
  print("Finished.")
}

The app opens upon running hi.app(), but when I close the app's window, the function calls the debugger:

Called from: Sys.sleep(0.001)

Desired behaviour:

  1. Run hi.app()
  2. Close app window
  3. print [1] "Finished"

Author:InspectorSands,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37737942/calling-shiny-app-as-part-of-a-function-in-r
yy