Skip to content

Instantly share code, notes, and snippets.

@yihui
Created February 7, 2012 01:34
Show Gist options
  • Save yihui/1756480 to your computer and use it in GitHub Desktop.
Save yihui/1756480 to your computer and use it in GitHub Desktop.
talk on gWidgets at 3rd ChinaR conference
# install.packages(c('gWidgetsRGtk2', 'gWidgetstcltk', 'gWidgetsrJava'))
library(gWidgets)
## different interfaces
options(guiToolkit = 'RGtk2')
g = gwindow('RGtk2')
gtext('RGtk2', container = g)
gbutton('RGtk2', container = g)
options(guiToolkit = 'tcltk')
g = gwindow('tcltk')
gtext('tcltk', container = g)
gbutton('tcltk', container = g)
options(guiToolkit = 'rJava')
g = gwindow('rJava')
gtext('rJava', container = g)
gbutton('rJava', container = g)
## button
options(guiToolkit = 'RGtk2')
g = gwindow('Demo')
gbutton('hello', handler = function(h, ...) {cat('Ouch!\n')}, container = g)
## check box / radio
gch = gcheckbox('checked?', container = g)
svalue(gch)
enabled(gch) = FALSE
gchg = gcheckboxgroup(LETTERS, container = g)
svalue(gchg)
svalue(gchg) = c('D', 'F', 'R')
gradio(letters, container = g)
## droplist
gdroplist(LETTERS, container = TRUE)
## message
gmessage('Bingo!')
gmessage('Hey!', title = 'Look out', icon = 'warning')
x = ginput('Say something:')
# alert box will disappear in 3 seconds
galert('Be careful!!!')
## text box
gedit(container = TRUE)
gtxt = gtext(container = TRUE)
svalue(gtxt) = c('line 1', 'line 2')
svalue(gtxt)
# key stroke event
addHandlerKeystroke(gtxt, handler = function(h, ...) galert('Ouch!', delay = .5))
## slider & ggroup()
x1 = x2 = x3 = 0
g = ggroup(horizontal = FALSE, container = TRUE)
gslider(from = 0, to = 1, by = 0.05, handler = function(h, ...) {
x1 <<- svalue(h$obj)
par(bg = rgb(x1, x2, x3))
plot.new()
}, container = g)
gslider(from = 0, to = 1, by = 0.05, handler = function(h, ...) {
x2 <<- svalue(h$obj)
par(bg = rgb(x1, x2, x3))
plot.new()
}, container = g)
gslider(from = 0, to = 1, by = 0.05, handler = function(h, ...) {
x3 <<- svalue(h$obj)
par(bg = rgb(x1, x2, x3))
plot.new()
}, container = g)
## glayout()
g = glayout(container = TRUE)
g[1,1] = 'red'
g[1,2,expand=TRUE] = gslider(from = 0, to = 1, by = 0.05, handler = function(h, ...) {
x1 <<- svalue(h$obj)
par(bg = rgb(x1, x2, x3))
plot.new()
}, container = g)
g[2,1] = 'green'
g[2,2,expand=TRUE] = gslider(from = 0, to = 1, by = 0.05, handler = function(h, ...) {
x2 <<- svalue(h$obj)
par(bg = rgb(x1, x2, x3))
plot.new()
}, container = g)
g[3,1] = 'blue'
g[3,2,expand=TRUE] = gslider(from = 0, to = 1, by = 0.05, handler = function(h, ...) {
x3 <<- svalue(h$obj)
par(bg = rgb(x1, x2, x3))
plot.new()
}, container = g)
## other widgets
gcalendar(container = TRUE)
g.df = gdf(iris, container = TRUE)
g.df[1, 2]
gframe('Frame 1', container = TRUE)
library(formatR)
library(iBUGS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment