-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseball_app.R
More file actions
82 lines (71 loc) · 2.01 KB
/
Copy pathbaseball_app.R
File metadata and controls
82 lines (71 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
library(shiny)
library(Lahman)
library(dplyr)
library(ggplot2)
#Data Setup
batting <- Batting %>%
select(
-playerID,
-stint,
-teamID,
-lgID
)%>%
mutate(SLG=((H-X2B-X3B-HR)+2*X2B+3*X3B+4*HR)/AB)%>%
mutate(AVG=H/AB)
ui <- fluidPage(
titlePanel("Batting Stats"),
sidebarLayout(
sidebarPanel(
selectInput("metric",
label = "Which metric would you like to see?",
choices = c("AVG",
"SLG",
"AB",
"G",
"R",
"H",
"X2B",
"X3B",
"HR",
"RBI",
"SB",
"CS",
"BB",
"SO",
"IBB",
"HBP",
"SH",
"SF",
"GIDP"
),
selected = "AVG"),
sliderInput("bins",
label = "Histogram bins",
min = 5, max = 100, value = 50),
selectInput("year",
label = "Year",
choices=rev(seq(min(batting$yearID),max(batting$yearID)))),
numericInput("min_AB",
label = "Minimum At-Bats",
value = 5,
step = 1,
min = 0, max=max(batting$AB))
),
mainPanel(
plotOutput("fig1")
)
)
)
server <- function(input, output) {
output$fig1 <- renderPlot({
batting%>%
filter(yearID==input$year)%>%
filter(AB>input$min_AB)%>%
select(VAR = input$metric)%>%
ggplot()+
geom_histogram(aes(x=VAR),bins=input$bins,fill="darkorchid")+
xlab(input$metric)
})
}
# Run the app ----
shinyApp(ui = ui, server = server)