[英]R Shiny app closes by itself after a while when running from R Studio, but it's still listening… is this normal?
[英]R: when running R App in cmd it loads and closes
我寫了一個 R 應用程序(帶有 gWidgets),它在 RStudio 中運行良好。
然而,當我創建 bat 文件時,它加載代碼就好了,它實際上打開了應用程序的第一個窗口,但隨后應用程序關閉並且沒有拋出錯誤。
我的批處理文件很簡單:
<path where R is installed> <path where my program is saved>
關於我的 R 代碼,它是 99% 的函數,但是我的最后一件事不是函數,而是打開歡迎窗口的代碼(簡化):
First_window <- gwindow("Welcome")
g <- ggroup(horizontal = FALSE, container = First_window)
gtext("Welcome to Recovery Plan application", container = g, expand=TRUE)
gtext("Do you want to start a new project or open an old one?", container = g)
gbutton("New project", container=g, handler=function(h,...) foo_function)
我需要做什么?
我建議您在腳本末尾添加gtkMain()
,它會循環直到發送銷毀消息。 請看下圖:
options("guiToolkit"="RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)
First_window <- gwindow("Welcome")
g <- ggroup(
horizontal = FALSE,
container = First_window)
gtext(
text = "Welcome to Recovery Plan application",
container = g,
expand=TRUE)
gtext(
text = "Do you want to start a new project or open an old one?",
container = g)
gbutton(
text = "New project",
container = g,
handler = function(h,...) gtkMainQuit)
gtkMain()
@echo off
"<path to R bin> \R.exe" CMD BATCH --no-save --no-restore "<path to R-file>\gtk.R"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.