TclTk package in R - Johns Hopkins University

Download Report

Transcript TclTk package in R - Johns Hopkins University

Tcl/Tk package in R
Yichen Qin
Department of Applied Mathematics and Statistics
December 5, 2008
1
Today’s schedule




Introduction to Tcl/Tk package in R.
Basic concepts in Tcl/Tk package
Some basic example
Some fancy examples (if time
permitted)
2
Introduction to Tcl/Tk
package
3
What is Tcl?

Tcl, or the "Tool Command Language",
is a powerfully simple, open sourcelicensed programming language. Tcl
provides basic language features such
as variables, procedures, and control
structures. It runs on almost any
modern OS. But the key feature of
Tcl is its extensibility.
4
What is Tk?


Tk is a Tcl extension, written in C,
designed to give the user a relatively
high level interface to his or her
windowing environment.
GUI (Graphical user interface)
extension
5
What is Tcl/Tk?

Tcl/Tk is a combination of a scripting
language and a toolkit for graphical
user interfaces.
6
What is Tcl/Tk package in R?

The Tcl/Tk package allows the use of
the Tk graphical user interface
elements from within R by embedding
Tk commands into the R language, and
replacing Tcl code with R function
calls.
7
Who developed it?



Peter Dalgaard developed this
package.
He is a professor at Department of
Biostatistics, University of
Copenhagen
Most examples and materials in our
class are from by him.
8
Language of Tcl/Tk package


R function instead of Tcl language.
Too many commands
9
Learning Method



The best way to learn Tcl/Tk package
is through examples.
There are relatively limited material
for this package, compare to other
packages.
The commands are so many that no
textbook will cover them all. So
learning while using is the best way.
10
Learning material



http://www.sciviews.org/_rgui/tcltk/
http://bioinf.wehi.edu.au/~wettenhall
/RTclTkExamples/
http://www.r-project.org/
11
Basic concepts in Tcl/Tk – R
with some examples
12
A basic component: Widget


A widget is a GUI (Graphical user
interface) element.
It can be: buttons, listboxes, text
editing windows, sliders, text entry
fields, labels, menus, and a canvas for
drawing graphics.
13
Widget example



R-prog1.R
R-prog2.R
R-prog7.R
14
Geometry managers




A geometry manager controls the
placement of widgets within a master
widget.
Tkplacer() --- hardly used
Tkpack() --- places widgets in order around
edges of cavity based on a order and a
direction.
Tkgrid() --- lays out widgets in rows and
columns
15
Tkpacker() example

R-prog12.R
16
Tkgrid() example

R-prog8.R
17
Connect widgets with R



We need a way to get data from
widgets to and from R, and a way to
make things happen in response to
widget events.
Tkconfigure() --- value-related
Tkbind() --- action-related
18
tkconfigure() example


R-prog14.R
R-prog9.R
19
Tkbind() example

R-prog10.R
20
Creat a menu




Menus are created in several steps. First
you setup the menu with tkmenu(), then you
add items with tkadd(). There are so many
possible options for a menu item that this
is a more practicable approach.
Add menu backwards
Tkmenu()
Tkadd()
21
Tkmenu() tkadd() example

R-prog4.R
22
Some more examples
23
examples



R-prog3.R
R-prog6.R
R-prog11.R
24
Some advance examples with
Tcl/Tk and rpanel

Rpanel is also a package that
developed based on Tcl/Tk.
25
Advanced examples







http://www.stats.gla.ac.uk/~adrian/rpanel/
R-prog15.R
R-prog16.R
R-prog17.R
R-prog18.R
R-prog19.R
R-prog20.R
26
Thank you



My contact information:
Email: [email protected]
Office: Whitehead 211E
27