Developing R
Graphical User
Interfaces
SETIA PRAMANA
Outlines
2
R GUI
Motivations
R GUI
IsoGeneGUI
neaGUI
How to develop an R GUI?
Independent GUI
Embedded GUI (RcmdrPlugin.BiclustGUI)
Summary
R Pros and Con
3
R GUI
Free open source and widely used.
Can be integrated with other languages (C/C++,
Java).
R can interact with many data sources and other
statistical packages (SAS, Stata, SPSS, and Minitab).
For the high performance computing task
multiple cores, either on a single machine or across a
network.
Users type commands to perform a
statistical analysis.
Is preferred for advanced users allows
direct control, more accurate, flexible and
the analysis is reproducible.
4
R GUI
R: A Command line
interface (CLI)
Requires good knowledge of the language
difficult for beginners or less frequent
users.
R provides tools for building GUIs
RGUI
5
R GUI
R: A Command line
interface (CLI)
6
R GUI
Graphical User Interface
(GUI)
A tool to provide an event-driven user interface.
An extra layer between the user and the program
Based on menus, dialog boxes, icons and controls.
Window, icon, menu, and pointing device
(WIMP) paradigm
R GUI Projects
7
R GUI
Integrated development environment (IDE)/Script
Editors aimed to provide feature-rich environments to
edit R scripts and code: Rstudio (www.rstudio.com),
and architect (www.Openanalytics.eu)
Web based application: the Rweb (Banfield, 1999),
R.Net (www.u.arizona.edu/~ryckman/Net.php), or
gWidgetsWWW (Verzani, 2012).
R Studio
R GUI
Download from
Rstudio.com
Powerfull IDE
(Integrated
Development
Environment) for
R.
R GUI Projects
9
R GUI
Python: OpenMeta-Analyst (Wallace et al, 2012)
Java: JGR (Java GUI for R), Deducer (Fellows,
2012), and Glotaran (Snellenburg, 2012).
Php: R-php (http://dssm.unipa.it/R-php/)
Shiny
C++, C#
Other extensions connect R to graphical
toolboxes for developing menus and dialog
boxes: Tcltk, Gtk.
We focus on Tcltk and Shiny
R GUI Tcl/Tk
10
R GUI
Most commonly used: easy, no additional
software needed and ready to be used in R
(tcltk package)
R-Tcl/Tk interface from the tcltk package
(Dalgaard, 2001 and Welch, 2000).
The tcltk package allows the use of the Tk
(toolkit) graphical user interface elements
within R by embedding Tk commands into
the R language.
11
R GUI
RGUI Developed using
tcltk
R GUI Tcl/Tk
12
R GUI
R GUIs developed by using tcl/tk or RGtk:
LimmaGUI (Wettenhall and Smyth, 2004),
LMMNorm (Haldermans, 2010),
IsoGeneGUI (Pramana et al. , 2010,
2012)
NeaGUI (Pramana et.al, 2013)
Rcommander (Fox, 2005)
RcmdrPlugin.biclustGUI (Pramana, 2011)
R GUI Tcl/Tk
13
R GUI
R GUIs developed by using tcl/tk or RGtk:
LimmaGUI (Wettenhall and Smyth, 2004),
LMMNorm (Haldermans, 2010),
IsoGeneGUI (Pramana et al. , 2010,
2012)
NeaGUI (Pramana et.al, 2013)
Rcommander (Fox, 2005)
RcmdrPlugin.biclustGUI (Pramana, 2011)
Independent
GUI
R GUI Tcl/Tk
14
R GUI
R GUIs developed by using tcl/tk or RGtk:
LimmaGUI (Wettenhall and Smyth, 2004),
LMMNorm (Haldermans, 2010),
IsoGeneGUI (Pramana et al. , 2010,
2011)
NeaGUI (Pramana et.al, 2013)
Rcommander (Fox, 2005)
RcmdrPlugin.biclustGUI (Pramana, 2011)
Embeded
GUI
neaGUI
15
R GUI
To help interpretation of
differentially expressed (DE)
genes in context of biological
processes, pathways and
networks.
Perform network enrichment
analysis.
Input: DE genes
Output: enriched pathways
statistics based on gene
interaction networks.
neaGUI Output
16
R GUI
neaGUI Output
17
R GUI
RGUI: RCommander
18
R GUI
Rcommander.com
Helpful for R
beginner
Install inside R
RGUI using C#: Wires
Developed by STIS
students
For Spatial Data
Analysis
Still developing
R GUI
19
RGUI using C#: Wires
20
R GUI
21
R GUI
RGUI: Web Based App
WebBUGS
Conducting
Bayesian Statistical
Analysis Online
Combines
OpenBUGS and R
www.webbugs.psychstat.org
R GUI
22
RGUI: Shiny
23
R GUI
A new package from Rstudio to build
interactive web applications with R.
Really Easy!
Build useful web applications with only a
few lines of codeno JavaScript required.
Self learning: http://shiny.rstudio.com/
http://www.showmeshiny.com/
RGUI using Shiny: FAST
Figure 5. FAST main page
24
RGUI, How to Build One?
25
R GUI
Choose one of RGUI categories, and tools to be used
(tcltk, java, etc.) which suit with the package purpose.
Make sketches of the window box and consider:
Input
Options
Output
Can all functions be run in a single window (e.g.
neaGUI)? Or a main window with menu
(IsoGeneGUI) and separate dialog boxes are needed?
Create Main Window
26
R GUI
tt <- tktoplevel()
tkwm.title(tt,"My New GUI")
topMenu <- tkmenu(tt)
tkconfigure (tt,menu=topMenu)
fileMenu <- tkmenu(topMenu,tearoff=FALSE)
openMenu <- tkmenu(topMenu,tearoff=FALSE)
tkadd(openMenu,"command",label="xls file",
command= getXls)
tkadd(openMenu,"command",label="text file)
Create Main Window
27
R GUI
tt <- tktoplevel()
tkwm.title(tt,"My New GUI")
topMenu <- tkmenu(tt)
tkconfigure (tt,menu=topMenu)
fileMenu <- tkmenu(topMenu,tearoff=FALSE)
openMenu <- tkmenu(topMenu,tearoff=FALSE)
getXls <- function
tkadd(openMenu,"command",label="xls
file", () {
fileName <- tclvalue(tkgetOpenFile(filetypes=
command= getXls)
gettext(' {"Excel Files" {".xls"}} {"All Files"
{"*"}}')))
tkadd(openMenu,"command",label="text
file)
data <- get( fileName) }
Create Main Window
28
R GUI
tt <- tktoplevel()
tkwm.title(tt,"My New GUI")
topMenu <- tkmenu(tt)
tkconfigure (tt,menu=topMenu)
fileMenu <- tkmenu(topMenu,tearoff=FALSE)
openMenu <- tkmenu(topMenu,tearoff=FALSE)
tkadd(openMenu,"command",label="xls file",
command= getXls)
tkadd(openMenu,"command",label="text file")
tkadd(fileMenu,"cascade",label="Open data",
menu=openMenu)
tkadd(fileMenu,"cascade",label="Edit data")
tkadd(fileMenu,"command",label="Quit",command=function() tkdestroy(tt))
tkadd(topMenu,"cascade",label="File",menu=fileMenu)
tkadd(topMenu,"cascade",label="Help")
tkfocus(tt)
Create a Dialog Box
29
R GUI
Create the window
require(tcltk)
tt<-tktoplevel()
tkwm.title(tt,"Input Window")
Edit Box
Name <- tclVar("")
entry.Name <-tkentry(tt,width="20",
textvariable=Name)
tkgrid(tklabel(tt,text="Name:"), entry.Name)
Create a Dialog Box
30
R GUI
Radio button
rb1 <- tkradiobutton(tt)
rb2 <- tkradiobutton(tt)
rbValue <- tclVar("Male")
tkconfigure(rb1,variable=rbValue,
value="Male")
tkconfigure(rb2,variable=rbValue,
value="Female")
tkgrid(tklabel(tt,text="Sex:"))
tkgrid(tklabel(tt,text="Male"),rb1)
tkgrid(tklabel(tt,text="Female"),rb2)
Create a Dialog Box
31
R GUI
List box with scroll bar
scr <- tkscrollbar(tt, repeatinterval=5,
command=function(...) tkyview(tl,...))
tl<-tklistbox(tt,height=4,selectmode="single",
background="white")
tkgrid(tklabel(tt,text="City:"), tl, scr)
city <- c("Brussels","Jakarta", "London",
"Stockholm")
for (i in (1:4)) tkinsert(tl,"end",city [i])
tkselection.set(tl,1)
tkgrid.configure(scr,rowspan=4,sticky="nsw")
Create a Dialog Box
32
R GUI
OK button
OK.but <-tkbutton(tt,text="
command=OnOK)
tkgrid(OK.but)
tkgrid.configure(OK.but)
tkfocus(tt)
OK
",
33
R GUI
Run the function (OK
button)
34
R GUI
Run the function (OK
button)
OnOK <- function() {
NameVal <- tclvalue(Name)
rbVal <- as.character(tclvalue
(rbValue))
if (rbVal=="Male") pref = "Mr."
if (rbVal=="Female") pref = "Mrs.
cityChoice <- city [as.numeric(tkcurselection(tl))+1]
tkdestroy(tt)
msg <- paste("Good morning ",pref , NameVal , "from", cityChoice,
tkmessageBox(message=msg)
}
sep=" ")
Summary
35
R GUI
A GUI could help novice R users for utilizing all the power of R.
Increase the use of our package/methods especially by scientists
with no/less knowledge of R.
Summary
36
R GUI
A GUI could help novice R users for utilizing all the power of R.
Increase the use of our package/methods especially by scientists
with no/less knowledge of R.
Things to consider in developing a GUI:
Type of GUI (spreadsheets, menu/dialog boxes),
Tool to develop (tcltk, java)
Embedded/Independent.
Single/Multi dialog boxes
Summary
37
R GUI
Make sure GUI is simple and user friendly.
Design Development Trial Packaging and Storing