【问题标题】:R: building a simple command line plotting tool/Capturing window close eventsR:构建一个简单的命令行绘图工具/捕获窗口关闭事件
【发布时间】:2011-03-05 00:55:49
【问题描述】:

我正在尝试在将充当简单命令行绘图工具的脚本中使用 R。 IE。用户在 csv 文件中管道,他们得到一个情节。我可以很好地使用 R 并通过各种临时文件机制显示绘图,但我遇到了障碍。在用户关闭窗口之前,我无法弄清楚如何让 R 继续运行。

如果我绘图并退出,绘图会立即消失。如果我绘制并使用某种无限循环,用户无法关闭绘图;他必须使用我不喜欢的中断退出。我看到有一个 getGraphicsEvent 函数,但它声称不支持该设备(X11)。无论如何,它似乎并不真正支持 onClose 事件,仅支持 onMouseDown。

关于如何解决这个问题的任何想法?

编辑:感谢 Dirk 提供检查 tk 界面的建议。这是我的有效测试代码:

require(tcltk)
library(tkrplot)

## function to display plot, called by tkrplot and embedded in a window
plotIt<-function(){ plot(x=1:10, y=1:10) }
## create top level window
tt<-tktoplevel()
## variable to wait on like a condition variable, to be set by event handler
done <- tclVar(0)
## bind to the window destroy event, set done variable when destroyed
tkbind(tt,"<Destroy>",function() tclvalue(done) <- 1)
## Have tkrplot embed the plot window, then realize it with tkgrid
tkgrid(tkrplot(tt,plotIt))
## wait until done is true
tkwait.variable(done)

【问题讨论】:

    标签: r plot x11


    【解决方案1】:

    您需要具有独特事件循环的东西 --- 而最好的便携 解决方案是依赖(已包含)tcltk 包。从它的演示开始。

    最简单的情况可能是

    > library(tcltk)
    > tk_messageBox(message="Press a key")
    

    这会弹出一个您需要确认才能继续的框。

    【讨论】:

      猜你喜欢
      • 2010-11-25
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2015-12-15
      相关资源
      最近更新 更多