Another beginner question. I've been through so many examples online but can't find one that will help me tailor this portion of my own GUI.
另一个初学者问题。我在网上经历了很多这样的例子,但找不到能帮我定制这部分GUI的例子。
As part of the GUI I'm piecing together for my R scripts I need to be able to populate comboboxes from a .csv file chosen by the user with the filebrowse command. I can see how to populate a combobox from a vector dataframe created within the script but I can't figure how to connect the newly imported file with the comboboxes.
作为GUI的一部分,我正在拼凑我的R脚本,我需要能够使用filebrowse命令从用户选择的.csv文件中填充组合框。我可以看到如何从脚本中创建的矢量数据框填充组合框,但我无法想象如何将新导入的文件与组合框连接起来。
#structure the main window
win1 <- gwindow( visible = TRUE)
g1 <- ggroup(container=win1, horizontal=FALSE)
df <- gfilebrowse("Select a csv file", container = g1)
#add two comboboxes, but how do I write this code to relate it to the user selected file?
cb1 <- gcombobox("X", cont = g1)
cb2 <- gcombobox("Y", cont = g1)
When the user selects the .csv file the two comboboxes should be populated with the column headers from df. For a simple relationship, lets just say the user would choose the X column and the Y column.
Next, these chosen column variables (X,Y) should be made available for use in other functions, equations, plots etc, probably actioned by a button. How would I do this? Thanks in advance
当用户选择.csv文件时,应使用df中的列标题填充两个组合框。对于简单的关系,我们只想说用户会选择X列和Y列。接下来,这些选择的列变量(X,Y)应该可用于其他函数,方程式,图表等,可能由按钮操作。我该怎么办?提前致谢
1 个解决方案
#1
1
Something expanding this pattern should work.
扩展这种模式的东西应该有效。
library(gWidgets)
w <- gwindow("Testing", visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)
fb <- gfilebrowse("Choose a CSV file", quote=FALSE,
filter = list("CSV files"=list(patterns="*.csv")),
cont=g)
cb <- gcombobox("", cont=g)
addHandlerChanged(fb, handler=function(h,...) {
x <- read.csv(svalue(fb))
cb[] <- colnames(x)
})
visible(w) <- TRUE
#1
1
Something expanding this pattern should work.
扩展这种模式的东西应该有效。
library(gWidgets)
w <- gwindow("Testing", visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)
fb <- gfilebrowse("Choose a CSV file", quote=FALSE,
filter = list("CSV files"=list(patterns="*.csv")),
cont=g)
cb <- gcombobox("", cont=g)
addHandlerChanged(fb, handler=function(h,...) {
x <- read.csv(svalue(fb))
cb[] <- colnames(x)
})
visible(w) <- TRUE