-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgWidgets0.r
executable file
·69 lines (60 loc) · 1.82 KB
/
gWidgets0.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env Rscript
require(gWidgets)
require(gWidgetstcltk)
## or gWidgetsGtk2
## or gWidgetsrJava
## or gWidgetsWWW
## or gWidgetsQt
win <- gwindow("Tab delimited file upload example") # very small window, hard to notice
## Group 1
grp_name <- ggroup(container = win)
## label
lbl_data_frame_name <- glabel(
"Variable to save data to: ",
container = grp_name
)
## txt box
txt_data_frame_name <- gedit("dfr", container = grp_name)
## Group 2
grp_upload <- ggroup(container = win)
## button
btn_upload <- gbutton(
text = "Upload tab delimited file",
container = grp_upload,
## button handler:
handler = function(h, ...) {
gfile(
text = "Upload tab delimited file",
type = "open",
action = ifelse(svalue(chk_eurostyle), "read.delim2", "read.delim"),
handler = function(h, ...)
{
tryCatch(
{
data_frame_name <- make.names(svalue(txt_data_frame_name))
the_data <- do.call(h$action, list(h$file))
assign(data_frame_name, the_data, envir = globalenv())
svalue(status_bar) <-
paste(nrow(the_data), "records saved to variable", data_frame_name)
},
error = function(e) svalue(status_bar) <- "Could not upload data"
)
},
filter = list(
"Tab delimited" = list(patterns = c("*.txt","*.dlm","*.tab")),
"All files" = list(patterns = c("*"))
)
)
}
)
use_comma_for_decimal <- function() {
unname(Sys.localeconv()["decimal_point"] == ",")
}
## checkbox
chk_eurostyle <- gcheckbox(
text = "Use comma for decimal place",
checked = use_comma_for_decimal(),
container = grp_upload
)
## status bar
status_bar <- gstatusbar("", container = win)