以编程方式启动R Shiny应用程序作为后台作业

问题描述

Dean Attali通过使用关闭按钮关闭了浏览器窗口并结束了Shiny会话,使用Shiny应用程序在how to exit elegantly上提供了一个精彩的示例。考虑以下示例(对Dean原始代码修改):

ui.r

library(shiny)
library(shinyjs)

jscode <- "shinyjs.closeWindow = function() { window.close(); }"

ui <- fluidPage(
  useShinyjs(),extendShinyjs(text = jscode,functions = c("closeWindow")),htmlOutput(outputId = "exitheading"),actionButton(inputId = "closeGUI",label = "Exit")
)

server.r

library(shiny)
library(shinyjs)

server <- function(input,output,session) {
  output$exitheading <- renderText("Press the button below to exit the app")
  observeEvent(input$closeGUI,{
    js$closeWindow()
    stopApp()
  })
}

并运行该应用程序:

runApp(appDir = "/tmp")

我的问题是有关如何以编程方式将Shiny应用程序作为后台作业启动,以便RStudio控制台免费供进一步使用(甚至可以并行启动第二个Shiny应用程序)仍在运行,然后使用上方应用程序中的退出按钮结束作业。我正在寻找一种可以添加到包含Shiny应用程序like this one的程序包中的解决方案。

我已阅读this并尝试了提供的示例应用程序,但仍需要用户手动干预。

有人可以协助吗?

解决方法

因此,正如我在评论中所提到的,您可以使用i==n-1来实现此目的,该命令基本上运行一个终端命令,并将systemwait标志设置为show.output.on.console

FALSE