如何使用gWidgets选项卡式笔记本切换活动设备?

时间:2014-07-27 03:18:16

标签: gwidgets

我用gWidgets创建了一个双标签GUI。图表嵌入在两个选项卡的每一个中。问题是两个图都被发送到选项卡2.如何切换或选择活动设备? gwidgets包的插图表示addHandlerChanged或ggraphicsnotebook。在使用ggraphicsnotebook时,会生成一些不需要的按钮。所以我想知道如何使用addHandlerChanged或其他方法。附上一个小例子。感谢。

# library
library(gWidgets); library(cairoDevice)
options(guiToolkit = "RGtk2")

# first tab -----------------------------------------------------------
r.main <- gwindow(title = "Correlation", visible = TRUE)
r.nb <- gnotebook(container = r.main)
rSta <- ggroup(container = r.nb, horizontal = TRUE, label = "Static")
rDyn <- ggroup(container = r.nb, horizontal = FALSE, label = "Dynamic")

ggraphics(container = rSta)
obj.ptNum <- gradio(items = c("100", "1,000", "5,000"), 
  selected = 2, horizontal = FALSE, container = rSta, 
  handler = function(h, ...) {plot(1:10, main = "Static graph")})

# second tab  -----------------------------------------------
obj.plotNum <- gradio(items = c("10", "50", "300", "400"), 
  selected = 2, horizontal = TRUE, container = rDyn, 
  handler = function(h, ...) {
    plot(30:35, col = 'red', main = "Dynamic graph")})
ggraphics(container = rDyn) 

编辑:我找到了一个解决方案。请注意,问题不在于选择选项卡,而在于选择当前活动的嵌入式设备。为了将来参考,我的代码将在下面复制。我无法弄清楚的一个小问题:如何在没有点击的情况下启动应用程序时显示图表?谢谢大家。

library(gWidgets); library(cairoDevice); library(gWidgetsRGtk2)
library(RGtk2)
options(guiToolkit = "RGtk2")

# first tab -----------------------------------------------------------
r.main <- gwindow(title = "Correlation", visible = TRUE)
r.nb <- gnotebook(container = r.main)
rSta <- ggroup(container = r.nb, horizontal = TRUE, label = "Static")

ggraphics(container = rSta)
staPlot <- function(h, ...) {
  sel <- ifelse(test = length(dev.list()) >= 2, yes = 2, no = 1) 
  dev.set(which = sel)
  plot(1:as.numeric(svalue(obj.ptNum)), main = "Static graph")}
obj.ptNum <- gradio(items = c("100", "150", "200"), 
  selected = 2, horizontal = FALSE, container = rSta, 
  handler = staPlot)

# second tab  -----------------------------------------------
rDyn <- ggroup(container = r.nb, horizontal = FALSE, label = "Dynamic")
dynPlot <- function(h, ...) {
  sel <- ifelse(test = length(dev.list()) >= 2, yes = 3, no = 1) 
  dev.set(which = sel)
  plot(1:as.numeric(svalue(obj.plotNum)), col = 'red', 
     main = "Dynamic graph")}
obj.plotNum <- gradio(items = c("10", "50", "300", "400"), 
  selected = 2, horizontal = TRUE, container = rDyn, 
  handler = dynPlot)
ggraphics(container = rDyn)
svalue(r.nb) <- 1

1 个答案:

答案 0 :(得分:0)

使用dev.set是不好的。如果要在图形设备中创建绘图,可以使用以下代码。

graph&lt; - ggraphics()

可见(图表)&lt; - TRUE

箱线图(...)