linux - 是否可以将 GUI 与 littler 一起使用?

标签 linux r gwidgets rscript

我想使用 Rscriptlittler 编写带有简单 GUI 的小脚本。 在示例中,我使用了 gWidget2RGtk2

例如,helloworld.R

#!/usr/bin/r
library(gWidgets2RGtk2)

W <- gwindow("Window", visible=FALSE)
L <- glabel("Hello World!", container=W)

visible(W) <- TRUE

如果它在 R session 中运行时效果很好,但从 shell 运行时会出错:

Error in UseMethod(".gwindow") : 
no applicable method for '.gwindow' applied to an object of class "NULL"

对于图形,我知道在使用 plot() 之前需要 X11()

是否可以修复此脚本以允许从 shell 渲染小部件?

(我只需要在linux机器上运行脚本)


编辑:这是一个在 Linux 上运行良好的示例。 (包括在回答和评论中收到的建议。)

#!/usr/bin/r
require(RGtk2) # required for gtkMain()
require(gWidgets2) 
options(guiToolkit="RGtk2")

W <- gwindow("Window", visible=FALSE, 
  handler = function(h, ...) {
    gtkMainQuit() # stop main loop when windows is closed.
  }
)
L <- glabel("Hello Word!", container=W)
visible(W) <- TRUE

gtkMain() # start main loop to keep the script alive.

最佳答案

是的,我过去曾这样做过。您必须确保有一个 GUI 事件循环正在运行,以通过等待使应用程序保持事件状态。

关于linux - 是否可以将 GUI 与 littler 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32706253/

相关文章:

c - unwind_frame 导致内核分页错误

linux - bash 中的自定义命令路径错误

Python jxmlease 问题

vnode 上的转换操作(在 NetBSD 中)

r - 如何在 R 中导入 matlab 表

r - 如何刷新 R gWidget 的内容?

r - 在 gWidgetsRGtk2 中使用 ggplot2

r - 在 ggplot x 轴上显示所有日期值 - R

r - R Shiny :删除ggplot2背景以使其透明

r - gWidgetRGtk2 gcheckbox 列表加法/减法循环