Permalink
Browse files

Initial commit

  • Loading branch information...
1 parent 564f661 commit 189484519fc2885792e8df1e0834e458ba0eb808 @psychemedia committed Nov 18, 2012
Showing with 76 additions and 0 deletions.
  1. +50 −0 f1djR/shinychamp/server.R
  2. +26 −0 f1djR/shinychamp/ui.R
View
50 f1djR/shinychamp/server.R
@@ -0,0 +1,50 @@
+library(shiny)
+library(ggplot2)
+
+# Define server logic required to generate and plot a random distribution
+shinyServer(function(input, output) {
+ points=data.frame(pos=1:11,val=c(25,18,15,12,10,8,6,4,2,1,0))
+ points[[1,2]]
+ a=245
+ v=255
+
+ pospoints=function(a,v,pdiff,points){
+ pp=matrix(ncol = nrow(points), nrow = nrow(points))
+ for (i in 1:nrow(points)){
+ for (j in 1:nrow(points))
+ pp[[i,j]]=v-a+pdiff[[i,j]]
+ }
+ pp
+ }
+
+ ppx=pospoints(a,v,pdiff,points)
+
+ winmdiff=function(vadiff,pdiff,points){
+ win=matrix(ncol = nrow(points), nrow = nrow(points))
+ for (i in 1:nrow(points)){
+ for (j in 1:nrow(points))
+ if (i==j) win[[i,j]]=''
+ else if ((vadiff+pdiff[[i,j]])>=0) win[[i,j]]='VET'
+ else win[[i,j]]='ALO'
+ }
+ win
+ }
+
+ # Function that generates a plot of the distribution. The function
+ # is wrapped in a call to reactivePlot to indicate that:
+ #
+ # 1) It is "reactive" and therefore should be automatically
+ # re-executed when inputs change
+ # 2) Its output type is a plot
+ #
+ output$distPlot <- reactivePlot(function() {
+ wmd=winmdiff(ppx[[input$vet,input$alo]],pdiff,points)
+ wmdm=melt(wmd)
+ g=ggplot(wmdm)+geom_text(aes(X1,X2,label=value,col=value))
+ g=g+xlab('VET position in Brazil')+ ylab('ALO position in Brazil')
+ g=g+labs(title="Championship outcomes in Brazil")
+ g=g+ theme(legend.position="none")
+ g=g+scale_x_continuous(breaks=seq(1, 11, 1))+scale_y_continuous(breaks=seq(1, 11, 1))
+ print(g)
+ })
+})
View
26 f1djR/shinychamp/ui.R
@@ -0,0 +1,26 @@
+library(shiny)
+
+shinyUI(pageWithSidebar(
+
+ # Application title
+ headerPanel("F1 Driver Championship Scenarios"),
+
+ # Sidebar with a slider input for number of observations
+ sidebarPanel(
+ sliderInput("alo",
+ "ALO race pos in United States Grand Prix:",
+ min = 1,
+ max = 11,
+ value = 1),
+ sliderInput("vet",
+ "VET race pos in United States Grand Prix:",
+ min = 1,
+ max = 11,
+ value = 2)
+ ),
+
+ # Show a plot of the generated distribution
+ mainPanel(
+ plotOutput("distPlot")
+ )
+))

0 comments on commit 1894845

Please sign in to comment.