如何为gWidget提供功能以及如何将用户的输入用于'gedit'?

时间:2016-11-12 17:49:46

标签: r user-interface rstudio gedit gwidgets

`win <- gwindow(title = "Analysing PDB structures", visible=TRUE, name=title,
           width = NULL, height = NULL, parent=NULL)
group <- ggroup(horizontal = FALSE, container=win)
obj <- glabel("Type your PDB code here:", container = group)
obj <- gedit("", container=group)
obj <- gbutton("Go", container = group)`

当用户向gedit输入一个值并按下gbutton“Go”时,如何让后续代码(例如install.packages(bio3d))自动运行?

编辑:在回复帖子后,我设法完成了这项功能,谢谢。 如何在obj3中的obj2中的'gedit'中利用用户给出的输入?我究竟做错了什么?

win <- gwindow(title = "Analysing PDB structures", 
           visible=TRUE, name=title,
           width = NULL, height = NULL, parent=NULL)
group <- ggroup(horizontal = FALSE, container=win)
obj1 <- glabel("Type your PDB code here:", container = group)
innergroup <- ggroup(container = group)
obj2 <- gedit((file1<-""), container=innergroup)
obj3<-addHandlerChanged(obj2, handler=function(...){
  gbutton( "Go", container = innergroup, 
       handler = function( h, ... ) {
         gmessage( svalue( obj2 ), title = (pdb<- read.pdb(file1)))
       } )
 })

1 个答案:

答案 0 :(得分:0)

只需添加处理程序:

win <- gwindow( title = "Analysing PDB structures", 
                visible=TRUE, name=title,
                width = NULL, height = NULL, parent=NULL)
group <- ggroup( horizontal = FALSE, container=win )
obj1 <- glabel( "Type your PDB code here:", container = group )
obj2 <- gedit( "", container = group )
obj3 <- gbutton( "Go", container = group, 
                handler = function( h, ... ) {
    gmessage( svalue( obj2 ), title = "" )
} )

将您的代码改为gmessage(),或者先定义您的函数,然后按名称引用它:handler = foo。必须按照这种模式定义该函数:

foo <- function( h, ... )
{ 
    gmessage( svalue( obj2 ), title = "" )
}