Skip to content

Instantly share code, notes, and snippets.

@calpolystat
Last active June 29, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calpolystat/d40a02fa87508ac5ac4b to your computer and use it in GitHub Desktop.
Save calpolystat/d40a02fa87508ac5ac4b to your computer and use it in GitHub Desktop.
Chaos Game -- 2 Dimensions: Shiny app at http://www.statistics.calpoly.edu/shiny
Chaos Game in 2 Dimensions Shiny App
Base R code created by Jimmy Doi
Shiny app files created by Jimmy Doi
Cal Poly Statistics Dept Shiny Series
http://statistics.calpoly.edu/shiny
Title: Chaos Game -- 2 Dimensions
Author: Jimmy Doi
AuthorUrl: http://www.calpoly.edu/~jdoi
License: MIT
DisplayMode: Normal
Tags: Chaos game, fractal, random
Type: Shiny
The MIT License (MIT)
Copyright (c) 2015 Jimmy Doi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# ----------------------------------------
# App Title: Chaos Game -- 2 Dimensions
# Author: Jimmy Doi
# ----------------------------------------
library(shiny)
library(shinyBS)
library(shape)
###################################################################
# Triangle
###################################################################
tri.gen <- function(wt){
weight <- wt
len <- 50000
# loci matrix to contain all endpoints
loci <- matrix(NA,ncol=3,nrow=3)
loci[1,] <- c(1,0,0)
loci[2,] <- c(2,0.5,sqrt(3)/2)
loci[3,] <- c(3,1,0)
# vertices contains all random vertex points
vertices <- runif(len)
vertices[which(vertices>2/3)]<- 3
vertices[which(1/3<vertices & vertices<=2/3)]<- 2
vertices[which(vertices<=1/3)]<- 1
coords <- matrix(NA,ncol=2,nrow=(len+1))
colnames(coords)<-c("x","y") #needed for ggvis
coords[1,] <- c(runif(1),runif(1)*sqrt(3)/2)
for (i in 1:len){
row <- i+1
spot <- which(loci[,1]==vertices[i])
x <- loci[spot,2]
y <- loci[spot,3]
x.new <- weight*x + (1-weight)*coords[i,1]
y.new <- weight*y + (1-weight)*coords[i,2]
coords[row,]<-c(x.new,y.new)
x <- x.new
y <- y.new
}
return(list(loci,vertices,coords))
}
###################################################################
# Square
###################################################################
sqr.gen <- function(wt){
weight <- wt
len <- 50000
# loci matrix to contain all endpoints
loci <- matrix(NA,ncol=3,nrow=8)
loci[1,] <- c(1,0.0,0.0)
loci[2,] <- c(2,0.5,0.0)
loci[3,] <- c(3,1.0,0.0)
loci[4,] <- c(4,1.0,0.5)
loci[5,] <- c(5,1.0,1.0)
loci[6,] <- c(6,0.5,1.0)
loci[7,] <- c(7,0.0,1.0)
loci[8,] <- c(8,0.0,0.5)
# vertices contains all random vertex points
vertices <- runif(len)
vertices[which(vertices>7/8)]<- 8
vertices[which(6/8<vertices & vertices<=7/8)]<- 7
vertices[which(5/8<vertices & vertices<=6/8)]<- 6
vertices[which(4/8<vertices & vertices<=5/8)]<- 5
vertices[which(3/8<vertices & vertices<=4/8)]<- 4
vertices[which(2/8<vertices & vertices<=3/8)]<- 3
vertices[which(1/8<vertices & vertices<=2/8)]<- 2
vertices[which(vertices<=1/8)]<- 1
coords <- matrix(NA,ncol=2,nrow=(len+1))
colnames(coords)<-c("x","y") #needed for ggvis
# randomly selected initial point in field of view
coords[1,] <- c(runif(1),runif(1))
for (i in 1:len){
row <- i+1
spot <- which(loci[,1]==vertices[i])
x <- loci[spot,2]
y <- loci[spot,3]
x.new <- (weight)*x + (1-weight)*coords[i,1]
y.new <- (weight)*y + (1-weight)*coords[i,2]
coords[row,]<-c(x.new,y.new)
}
return(list(loci,vertices,coords))
}
###################################################################
# Pentagon
###################################################################
pent.gen <- function(wt){
weight <- wt
len <- 50000
# loci matrix to contain all endpoints
loci <- matrix(NA,ncol=3,nrow=5)
c1 <- 0.25*(sqrt(5)-1)
c2 <- 0.25*(sqrt(5)+1)
s1 <- 0.25*(sqrt(10+2*sqrt(5)))
s2 <- 0.25*(sqrt(10-2*sqrt(5)))
loci[1,] <- c(1,0,1)
loci[2,] <- c(2,s1,c1)
loci[3,] <- c(3,s2,-c2)
loci[4,] <- c(4,-s2,-c2)
loci[5,] <- c(5,-s1,c1)
# vertices contains all random vertex points
vertices <- runif(len)
vertices[which(vertices>4/5)]<- 5
vertices[which(3/5<vertices & vertices<=4/5)]<- 4
vertices[which(2/5<vertices & vertices<=3/5)]<- 3
vertices[which(1/5<vertices & vertices<=2/5)]<- 2
vertices[which(vertices<=1/5)]<- 1
coords <- matrix(NA,ncol=2,nrow=(len+1))
colnames(coords)<-c("x","y") #needed for ggvis
# randomly selected initial point in field of view
coords[1,] <- c(runif(1,-s1,s1),runif(1,-c2,1))
for (i in 1:len){
row <- i+1
spot <- which(loci[,1]==vertices[i])
x <- loci[spot,2]
y <- loci[spot,3]
x.new <- (weight)*x + (1-weight)*coords[i,1]
y.new <- (weight)*y + (1-weight)*coords[i,2]
coords[row,]<-c(x.new,y.new)
}
return(list(loci,vertices,coords))
}
###################################################################
# Hexagon
###################################################################
hex.gen <- function(wt){
weight <- wt
len <- 50000
# loci matrix to contain all endpoints
loci <- matrix(NA,ncol=3,nrow=6)
alpha <- 0.5
beta <- sqrt(3)/2
loci[1,] <- c(1,0,2*alpha)
loci[2,] <- c(2,beta,alpha)
loci[3,] <- c(3,beta,-alpha)
loci[4,] <- c(4,0,-2*alpha)
loci[5,] <- c(5,-beta,-alpha)
loci[6,] <- c(6,-beta,alpha)
# vertices contains all random vertex points
vertices <- runif(len)
vertices[which(vertices>5/6)]<- 6
vertices[which(4/6<vertices & vertices<=5/6)]<- 5
vertices[which(3/6<vertices & vertices<=4/6)]<- 4
vertices[which(2/6<vertices & vertices<=3/6)]<- 3
vertices[which(1/6<vertices & vertices<=2/6)]<- 2
vertices[which(vertices<=1/6)]<- 1
coords <- matrix(NA,ncol=2,nrow=(len+1))
colnames(coords)<-c("x","y") #needed for ggvis
# randomly selected initial point in field of view
coords[1,] <- c(runif(1,-beta,beta),runif(1,-2*alpha,2*alpha))
for (i in 1:len){
row <- i+1
spot <- which(loci[,1]==vertices[i])
x <- loci[spot,2]
y <- loci[spot,3]
x.new <- (weight)*x + (1-weight)*coords[i,1]
y.new <- (weight)*y + (1-weight)*coords[i,2]
coords[row,]<-c(x.new,y.new)
}
return(list(loci,vertices,coords))
}
##############################################################################
# Shiny Server Contents
##############################################################################
shinyServer(function(input, output, session) {
output$my.init <- renderUI({
input$shape
sliderInput(inputId = "init",
"Number of points (n):",
min = 1,
max = 100,
step = 1,
value = 1,
animate=animationOptions(interval = 1000))
})
output$my.extend <- renderUI({
input$shape
sliderInput("extend",
"Number of points (n):",
min = 100,
max = 1000,
step = 25,
value = 100,
animate=animationOptions(interval = 400))
})
output$my.pts <- renderUI({
input$shape
sliderInput("pts",
"Number of points (n):",
min = 1000,
max = 50000,
step = 1000,
value = 1000,
animate=animationOptions(interval = 200))
})
updateButton(session, "gen", style = "primary", size = "default", disabled = FALSE)
all.list <- reactive({
if (input$shape == "tri") {
return(tri.gen(input$dist.tri*(input$gen>-1)))
}
if (input$shape == "sqr") {
return(sqr.gen(input$dist.sqr*(input$gen>-1)))
}
if (input$shape == "pent") {
return(pent.gen(input$dist.pent*(input$gen>-1)))
}
if (input$shape == "hex") {
return(hex.gen(input$dist.hex*(input$gen>-1)))
}
})
##################################
# initPlot #
##################################
output$initPlot <- renderPlot({
loci <- all.list()[[1]]
vertices <- all.list()[[2]]
coords <- all.list()[[3]]
#############################
# Triangle:INIT #
#############################
if (input$shape == "tri") {
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(0,1),ylim=c(0,sqrt(3)/2),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
if (!is.null(input$init)) {
if (input$init==1) {
points(coords[1,1],coords[1,2],pch=20,cex=3,col="blue")
if (coords[1,1]>=0.5 & coords[1,2]<=sqrt(3)/4) {
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]>=0.5 & coords[1,2]>sqrt(3)/4) {
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]<0.5 & coords[1,2]>sqrt(3)/4) {
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=4)
}
if (coords[1,1]<0.5 & coords[1,2]<=sqrt(3)/4) {
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=4)
}
}
}
}
#############################
# Square:INIT #
#############################
if (input$shape == "sqr") {
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(0,1),ylim=c(0,1),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
if (input$init==1) {
points(coords[1,1],coords[1,2],pch=20,cex=3,col="blue")
if (coords[1,1]>=0.5 & coords[1,2]<=0.5) { # LOWER RIGHT
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]>=0.5 & coords[1,2]>0.5) { # UPPER RIGHT
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]<0.5 & coords[1,2]>0.5) { # UPPER LEFT
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=4)
}
if (coords[1,1]<0.5 & coords[1,2]<=0.5) { # LOWER LEFT
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=4)
}
}
}
#############################
# Pentagon:INIT #
#############################
if (input$shape == "pent") {
c1 <- 0.25*(sqrt(5)-1)
c2 <- 0.25*(sqrt(5)+1)
s1 <- 0.25*(sqrt(10+2*sqrt(5)))
s2 <- 0.25*(sqrt(10-2*sqrt(5)))
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(-s1,s1),ylim=c(-c2,1),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
if (input$init==1) {
points(coords[1,1],coords[1,2],pch=20,cex=3,col="blue")
if (coords[1,1]>=0 & coords[1,2]<=0) { # LOWER RIGHT
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]>=0 & coords[1,2]>0) { # UPPER RIGHT
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]<0 & coords[1,2]>0) { # UPPER LEFT
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=4)
}
if (coords[1,1]<0 & coords[1,2]<=0) { # LOWER LEFT
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=4)
}
}
}
#############################
# Hexagon:INIT #
#############################
if (input$shape == "hex") {
alpha <- 0.5
beta <- sqrt(3)/2
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(-beta,beta),ylim=c(-2*alpha,2*alpha),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
if (input$init==1) {
points(coords[1,1],coords[1,2],pch=20,cex=3,col="blue")
if (coords[1,1]>=0 & coords[1,2]<=0) { # LOWER RIGHT
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]>=0 & coords[1,2]>0) { # UPPER RIGHT
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=2)
}
if (coords[1,1]<0 & coords[1,2]>0) { # UPPER LEFT
text(coords[1,1],coords[1,2]-0.04,"Random Starting Point",col="blue",pos=4)
}
if (coords[1,1]<0 & coords[1,2]<=0) { # LOWER LEFT
text(coords[1,1],coords[1,2]+0.04,"Random Starting Point",col="blue",pos=4)
}
}
}
##################################################################################
### APPLIED TO ALL
if (!is.null(input$init)) {
if (input$init!=1) {
points(coords[1:input$init-1,1],coords[1:input$init-1,2],pch=20,cex=1,col="blue")
points(coords[input$init-1,1],coords[input$init-1,2],pch=20,cex=2.75,col="blue")
points(coords[input$init,1],coords[input$init,2],pch=21,cex=3,col="blue",bg="white")
points(coords[input$init,1],coords[input$init,2],pch=20,cex=2.75,col="blue")
x0 <- coords[input$init-1,1]
y0 <- coords[input$init-1,2]
x1 <- coords[input$init,1]
y1 <- coords[input$init,2]
Arrows((.6*x0+.4*x1),(.6*y0+.4*y1),(.4*x0+.6*x1),(.4*y0+.6*y1),col="blue",lwd=2)
v.x <- loci[loci[,1]==vertices[input$init-1],2]
v.y <- loci[loci[,1]==vertices[input$init-1],3]
points(v.x,v.y,pch=1,cex=4,lwd=2)
points(v.x,v.y,pch=1,cex=3,lwd=2)
}
}
points(loci[,2],loci[,3],pch=20,cex=2,col="red")
}) # initPlot's renderPlot
##################################
# extendPlot #
##################################
output$extendPlot <- renderPlot({
loci <- all.list()[[1]]
vertices <- all.list()[[2]]
coords <- all.list()[[3]]
#############################
# Triangle:EXTEND #
#############################
if (input$shape == "tri") {
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(0,1),ylim=c(0,sqrt(3)/2),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
#############################
# Square:EXTEND #
#############################
if (input$shape == "sqr") {
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(0,1),ylim=c(0,1),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
#############################
# Pentagon:EXTEND #
#############################
if (input$shape == "pent") {
c1 <- 0.25*(sqrt(5)-1)
c2 <- 0.25*(sqrt(5)+1)
s1 <- 0.25*(sqrt(10+2*sqrt(5)))
s2 <- 0.25*(sqrt(10-2*sqrt(5)))
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(-s1,s1),ylim=c(-c2,1),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
#############################
# Hexagon:EXTEND #
#############################
if (input$shape == "hex") {
alpha <- 0.5
beta <- sqrt(3)/2
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(-beta,beta),ylim=c(-2*alpha,2*alpha),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
############################################################################
### APPLIED TO ALL
if (!is.null(input$extend)) {
if (input$extend!=0) {
points(coords[1:input$extend,1],coords[1:input$extend,2],pch=20,cex=1,col="blue")
}
}
points(loci[,2],loci[,3],pch=20,cex=2,col="red")
}) # extendPlot's renderPlot
##################################
# compPlot #
##################################
output$compPlot <- renderPlot({
loci <- all.list()[[1]]
vertices <- all.list()[[2]]
coords <- all.list()[[3]]
#############################
# Triangle:COMPLETE #
#############################
if (input$shape == "tri") {
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(0,1),ylim=c(0,sqrt(3)/2),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
#############################
# Square:COMPLETE #
#############################
if (input$shape == "sqr") {
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(0,1),ylim=c(0,1),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
#############################
# Pentagon:COMPLETE #
#############################
if (input$shape == "pent") {
c1 <- 0.25*(sqrt(5)-1)
c2 <- 0.25*(sqrt(5)+1)
s1 <- 0.25*(sqrt(10+2*sqrt(5)))
s2 <- 0.25*(sqrt(10-2*sqrt(5)))
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(-s1,s1),ylim=c(-c2,1),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
#############################
# Hexagon:COMPLETE #
#############################
if (input$shape == "hex") {
alpha <- 0.5
beta <- sqrt(3)/2
par(mar=c(0.5,0.5,0.5,0.5))
plot(0,0,xlim=c(-beta,beta),ylim=c(-2*alpha,2*alpha),col=0,
yaxt="n",xaxt="n",xlab="",ylab="",bty="n")
}
##############################################################################
### APPLIED TO ALL
if (!is.null(input$pts)) {
if (input$pts!=0) {
points(coords[1:input$pts,1],coords[1:input$pts,2],pch=".",cex=2.5,col="blue")
}
}
points(loci[,2],loci[,3],pch=20,cex=2,col="red")
}) # compPlot's renderPlot
})
# ----------------------------------------
# App Title: Chaos Game -- 2 Dimensions
# Author: Jimmy Doi
# ----------------------------------------
if (!require("shiny")) install.packages("shiny")
if (!require("shinyBS")) install.packages("shinyBS")
library(shiny)
library(shinyBS)
shinyUI(fluidPage(
tags$head(tags$link(rel = "icon", type = "image/x-icon", href =
"https://webresource.its.calpoly.edu/cpwebtemplate/5.0.1/common/images_html/favicon.ico")),
tags$head(
tags$style(HTML("hr {border-top: 1px solid #000000;}"))
),
tags$title("Chaos Game -- 2 Dimensions"),
h3("Chaos Game: Two Dimensions"),
div("Note: Please adjust width of browser if only one column is visible.",br(),
span(HTML("<a href='http://shiny.stat.calpoly.edu/ChaosGame3D' style='color: #DC143C'
target='_blank'>[Click here for another Shiny app on the Chaos Game]</a>")),
style = "font-size: 9pt;color:teal"),br(),
p("In the two dimensional version of the ", HTML("<a href='http://mathworld.wolfram.com/ChaosGame.html'>Chaos Game</a>"),
"we start with a regular polygon and mark selected
points which will typically be the vertices. These points will be called",
tags$i("endpoints"), "and will be marked in red. The game begins by randomly choosing a
starting point and one of the endpoints.
Mark a new point at a fixed distance ratio from the starting point to the endpoint (e.g.,
halfway to the endpoint). Select another endpoint at random and,
with the most recently created point, repeat the process to generate the next point
and continue. By applying the right distance ratio the resulting set of points can converge
to a beautiful image known as a", HTML("<i>fractal</i>"),". For each polygon the required
distance ratio to yield a fractal will be provided,
but try different settings to see what other patterns may arise!"
),
br(),
fluidRow(
column(4,
wellPanel(
selectizeInput('shape', h5(tags$b('Shape')), choices = list(
"Two Dimensions" = c(`Triangle` = 'tri',
`Square` = 'sqr',
`Pentagon` = 'pent',
'Hexagon' = 'hex')
), selected = 'tri'),
#hr(),
conditionalPanel(
condition = "input.shape=='tri'",
sliderInput("dist.tri",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .50, step=.01),
div("For", tags$b("Triangle"), "default value is 0.50",
style = "font-size: 9.5pt;color:teal",align="left")
),
conditionalPanel(
condition = "input.shape=='sqr'",
sliderInput("dist.sqr",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .67, step=.01),
div("For", tags$b("Square"), "default value is 0.67 (2/3)",
style = "font-size: 9.5pt;color:teal",align="left")
),
conditionalPanel(
condition = "input.shape=='pent'",
sliderInput("dist.pent",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .63, step=.01),
div("For", tags$b("Pentagon"), "default value is 0.63 (5/8)",
style = "font-size: 9.5pt;color:teal",align="left")
),
conditionalPanel(
condition = "input.shape=='hex'",
sliderInput("dist.hex",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .67, step=.01),
div("For", tags$b("Hexagon"), "default value is 0.67 (2/3)",
style = "font-size: 9.5pt;color:teal",align="left")
),
conditionalPanel(
condition = "input.shape=='tetra'",
sliderInput("dist.tetra",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .5, step=.01),
div("For", tags$b("Tetrahedron"), "default value is 0.50",
style = "font-size: 9.5pt;color:teal",align="left")
),
conditionalPanel(
condition = "input.shape=='cube'",
sliderInput("dist.cube",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .33, step=.01),
div("For", tags$b("Cube"), "default value is 0.33",
style = "font-size: 9.5pt;color:teal",align="left")
),
conditionalPanel(
condition = "input.shape=='dodec'",
sliderInput("dist.dodec",
label = h5(tags$b("Distance ratio to endpoint:")),
min = 0.01, max = .99, value = .38, step=.01),
div("For", tags$b("Dodecahedron"), "default value is 0.38",
style = "font-size: 9.5pt;color:teal",align="left")
) # NO COMMA AFTER RIGHT PARENT OF LAST CONDITIONALPANEL
,
#hr(),
br(),
conditionalPanel(condition="input.tabselected==1",
div(uiOutput("my.init")),
div("Press the",
span(HTML("&#9654"),style=
"font-size:10pt;color:#999999;"), "button above to animate.",br(),
span("Advance slider manually at anytime."),br(),
span("Click",tags$b("Randomize"),"to re-randomize at current n."),
align="center",style="font-size:8.5pt;color:teal")
),
conditionalPanel(condition="input.tabselected==2",
div(uiOutput("my.extend")),
div("Press the",
span(HTML("&#9654"),style=
"font-size:10pt;color:#999999;"), "button above to animate.",br(),
span("Advance slider manually at anytime."),br(),
span("Click",tags$b("Randomize"),"to re-randomize at current n."),
align="center",style="font-size:8.5pt;color:teal")
),
conditionalPanel(condition="input.tabselected==3",
div(uiOutput("my.pts")),
div("Press the",
span(HTML("&#9654"),style=
"font-size:10pt;color:#999999;"), "button above to animate.",br(),
span("Advance slider manually at anytime."),br(),
span("Click",tags$b("Randomize"),"to re-randomize at current n."),
align="center",style="font-size:8.5pt;color:teal")
),
#hr(),
br(),
# div(bsActionButton("gen", label="Randomize"),align="right"),
div(bsButton("gen", label="Randomize"),align="right"),
div("Click", tags$b("Randomize")," to re-randomize outcomes based on current settings.",
style = "font-size: 9.5pt;color:teal",align="right"),
br(),
div("Shiny app by",
a(href="http://statweb.calpoly.edu/jdoi/",target="_blank",
"Jimmy Doi"),align="right", style = "font-size: 8pt"),
div("Base R code by",
a(href="http://statweb.calpoly.edu/jdoi/",target="_blank",
"Jimmy Doi"),align="right", style = "font-size: 8pt"),
div("Shiny source files:",
a(href="https://gist.github.com/calpolystat/d40a02fa87508ac5ac4b",
target="_blank","GitHub Gist"),align="right", style = "font-size: 8pt"),
div(a(href="http://www.statistics.calpoly.edu/shiny",target="_blank",
"Cal Poly Statistics Dept Shiny Series"),align="right", style = "font-size: 8pt")
) #sidebarPanel
), #column-4
# Show a tabset that includes a plot, summary, and table view
# of the generated distribution
column(8,
tabsetPanel(type = "tabs",id = "tabselected",
##############
# tabPanel 1 #
##############
tabPanel("Initial Sequence",value=1,
fluidRow(
column(12,
div(
div(
plotOutput("initPlot"),style="width:500px",inline="TRUE"),align="center"),
HTML("<hr style='height: 2px; color: #BDBDBD; background-color: #D9D9D9; border: none;'>")
), # column-12
fluidRow(
column(10, offset=1,
p("
This plot shows a step-by-step progression of the chaos game.
At each step the randomly chosen red endpoint will be marked.
Use the 'Number of points' slider and press the",
span(HTML("&#9654"),style=
"font-size:10pt;color:#999999;"),"button to animate the plot.
Advance the slider to n=100 before moving to the 'Extended Sequence' tab.",
style="color:#0066CC"
)
) # column-10
) # fluidRow
) # fluidRow
), # tabPanel
##############
# tabPanel 2 #
##############
tabPanel("Extended Sequence",value=2,
fluidRow(
column(12,
div(
div(
plotOutput("extendPlot"),style="width:500px",inline="TRUE"),align="center"),
HTML("<hr style='height: 2px; color: #BDBDBD; background-color: #D9D9D9; border: none;'>")
), # column-12
fluidRow(
column(10, offset=1,
p("
Compare the plot above when n=100 to the plot when n=100 from the
'Initial Sequence' tab",HTML("&ndash;"), "they should be identical. This shows the plot
given above is simply a continuation of the chaos game.
Advance the 'Number of points' slider to n=1000 before moving to the 'Complete Sequence' tab.",
style="color:#0066CC"
)
) # column-10
) # fluidRow
) # fluidRow
), # tabPanel
##############
# tabPanel 3 #
##############
tabPanel("Complete Sequence",value=3,
fluidRow(
column(12,
div(
div(
plotOutput("compPlot"),style="width:500px",inline="TRUE"),align="center"),
HTML("<hr style='height: 2px; color: #BDBDBD; background-color: #D9D9D9; border: none;'>")
), # column-12
fluidRow(
column(10, offset=1,
p("
Compare the plot above when n=1000 to the plot when n=1000 from the
'Extended Sequence' tab",HTML("&ndash;"), "they should be identical.
This again shows the plot
given above is a continuation of the chaos game. Smaller plotting points are used
to reveal the finer details of the completed plot.",
style="color:#0066CC"
)
) # column-10
) #fluidRow
) #fluidRow
) # close tabPanel-Complete
)# tabsetPanel
)# column-8
) # fluidRow
)# fluidPage
)# shinyUI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment