简体   繁体   English

使用Tcltk构建GUI

[英]Building GUI with Tcltk

I'm very new in R and I'm trying to build a GUI using Tcltk package. 我是R的新手,我正在尝试使用Tcltk包构建GUI。 I'm not sure how the "tkGetOpenFile" works. 我不确定“tkGetOpenFile”是如何工作的。 I thought by using this function it would open and hold my dataset into the workspace of the RStudio. 我想通过使用这个函数,它会打开并将我的数据集保存到RStudio的工作区中。 But the only thing that happens is a popup window to choose the file. 但唯一发生的事情是弹出窗口来选择文件。

The code I'm using is below. 我正在使用的代码如下。

Please help me!!! 请帮我!!!

require(tcltk)
readCsv <- function(){
myval <- tkgetOpenFile()
mydata <- read.csv(paste(as.character(myval), collapse = " "))
assign("myData", mydata, envir = .GlobalEnv)
}

tt <- tktoplevel()
topMenu <- tkmenu(tt)           
tkconfigure(tt, menu = topMenu) 
fileMenu <- tkmenu(topMenu, tearoff = FALSE)
tkadd(fileMenu, "command", label = "Quit", command = function() tkdestroy(tt))
tkadd(fileMenu, "command", label = "Load", command = function() readCsv())
tkadd(topMenu, "cascade", label = "File", menu = fileMenu)
tkfocus(tt)

You need to use the tclvalue function to get an R character string representation of a Tcl variable. 您需要使用tclvalue函数来获取Tcl变量的R字符串表示。 Modify your function as follows: 修改您的功能如下:

readCsv <- function(){
   myval <- tclvalue(tkgetOpenFile()) # add `tclvalue` here
   mydata <- read.csv(myval) # then `myval` is a character string
   assign("myData", mydata, envir = .GlobalEnv)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM