R GUI with rpanel

Sometime we need R to be smart enough to under interactive control coming from the user, and under this circumstance the package RPANEL is a solution. Here is a toy model I wrote.

#==================================================================================
# Chaos demo 1: Sensitive dependence on initial conditions
#               Pick up a number from the audience
# Lei Zhu, 10/04/2013
#-----------------------------------------------------------------------------------
# Load library
library(rpanel)
#-----------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
# Define the plot function
# The function used is: Yt=1.5*Yt-1^2-1
chaos.draw <- function(panel){
N <- 100
k <- 1.5
Diff <- as.numeric(panel$h.diff)
Diff1 <- Diff/30
Int1 <- (100-60)/30-1
Int2 <- Int1+Diff1
Numuber1 <- c()
Numuber1 <- c(Numuber1,Int1)
Numuber2 <- c()
Numuber2 <- c(Numuber2,Int2)
for(i in 2:N){
temp1 <- k*Numuber1[i-1]^2-1
Numuber1 <- c(Numuber1, temp1)
temp2 <- k*Numuber2[i-1]^2-1
Numuber2 <- c(Numuber2, temp2)
}
Numuber1 <- (Numuber1+1)*30+60
Numuber2 <- (Numuber2+1)*30+60
# Plot
dev.new(width=4, height=5)
par(mfrow=c(3,1))
par(mar=c(5.1,5,4.1,5.1)) #bottom, left, top, right 
plot(Numuber1,type="l",col="blue",ann=F,axes=F,lwd=2)
axis(1, at=pretty(seq(1,N,by=10)),lwd=3,cex.axis=1.5)
axis(2, at=pretty(Numuber1),lwd=3,cex.axis=1.5)
title(main=paste("(a) T1, ","Initial=",as.character(Numuber1[1]),sep=""),font.main=2,cex.main=2)
#title(ylab="Y1",font.main=2,cex.lab=1.5)
grid()
box(lwd=3)
par(mar=c(5.1,5,4.1,5.1)) #bottom, left, top, right 
plot(Numuber2,type="l",col="darkgreen",ann=F,axes=F,lwd=2)
axis(1, at=pretty(seq(1,N,by=10)),lwd=3,cex.axis=1.5)
axis(2, at=pretty(Numuber1),lwd=3,cex.axis=1.5)
title(main=paste("(b) T2, ","Initial=",as.character(Numuber1[1]),"+",as.character(Diff),sep=""),font.main=2,cex.main=2)
#title(ylab="Y2",font.main=2,cex.lab=1.5)
grid()
box(lwd=3)
par(mar=c(5.1,5,4.1,5.1)) #bottom, left, top, right 
plot(Numuber2-Numuber1,type="l",col="red",ann=F,axes=F,lwd=2)
axis(1, at=pretty(seq(1,N,by=10)),lwd=3,cex.axis=1.5)
axis(2, at=pretty(Numuber2-Numuber1),lwd=3,cex.axis=1.5)
#title(xlab="Time Step (t)",font.main=2,cex.lab=1.5)
title(main="(c) T2-T1",font.main=2,cex.main=2)
title(xlab="Time (t)",font.lab=2,cex.lab=2)
abline(h=0,col="black",lty=2,lwd=1)
grid()
box(lwd=3)
panel
}
#-----------------------------------------------------------------------------------
panel <- rp.control(panelname = "thepanel")
rp.textentry(panel,h.diff,chaos.draw,"Diffience in Initial", initval = "1",pos='left', font=50)      
    
rp.do(panel, chaos.draw)

#==================================================================================

Here is what I got: