Git Product home page Git Product logo

dataproducts's Introduction

---
title: "ReadMe"
author: "David Matsumura"
date: "September 27, 2015"
output: html_document
---

#Baseball Team Chooser Application

##Summary
This is an application built to help a person pick a baseball team.  It takes 3 inputs from the user: League, the minimun number of wins and if the team is playoff bound.

Then it filters the full team list based on that criteria and picks randomly from the remaining group.  It returns the logo of the team that it lands on.

##Summary of Program

###UI.R

```{r eval=FALSE}
library(shiny)

shinyUI(pageWithSidebar(
  headerPanel("For Whom Should I Cheer?"),
  sidebarPanel(
    selectInput("league", "Which League?", 
                choices = c("National",
                           "American")),
    sliderInput('wins',"Minimun Number of Wins",min=1,max=100,value=50),
    radioButtons("playoffs", "Headed for the Playoffs?",
                 choices = c('Yes','Does not Matter'), selected = NULL, inline = FALSE)
    ),
  mainPanel(
    imageOutput('image')
  )
))
```

It is a very simple app.  It creates the header (headerPanel). There are 3 inputs in the sidebar panel, one select input (dropdown) one slider input and one radio button.  Then it creates a spot for the output.

###Server.R


```{r, eval=FALSE}
library(shiny)

wd.datapath = paste0(getwd(),"/data")
wd.init = getwd()
setwd(wd.datapath)

teamlistinitial <- read.csv('standings.csv',stringsAsFactors=FALSE)

setwd(wd.init)
```

The server code first has to build the team datalist out of a server side CSV file.

```{r eval=FALSE}
shinyServer(function(input, output) {
  data <- reactive({ 
    LG <- switch(input$league,
                  "National" = 'NL',
                  "American" = 'AL')
    PLAY <- switch(input$playoffs,
                 "Yes" = 10,
                 "No" = 32)
    teamlist <- teamlistinitial
    teamlist <- subset(teamlist,teamlist$Lg==LG)
    teamlist <- subset(teamlist,teamlist$W > input$wins)
    teamlist <- subset(teamlist,Rk < PLAY)
    team <- teamlist$Tm[sample(1:length(teamlist$Tm),1)]
  })=
```

To actually evaluate the inputs, the server function first translates them into values that can be applied to the source dataset.  Then it applies the filters and subsets the team list.

```{r eval=FALSE}
  output$team_image <- renderImage({
    src_link <- paste('images/',team(),'.jpg',sep='')
    alt_txt <- team()
    return(list(
        src = src_link,
        contentType = "image/jpg",
        alt = alt_txt
      ))
    }, deleteFile = FALSE)
  
})
```

After the team is picked, the server calls up the matching logo from the image folder and pushes it to the output.

One useful tip: The ouput of the reactive function is a closure. It is not subsettable, nor is it coerceable to a character.  The best way to use it is to call it as is with '()' after.  (See team() being called to get the image.)

dataproducts's People

Contributors

davidkunio avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.