TimStats commited on
Commit
f5a679a
·
verified ·
1 Parent(s): 04afbee

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +88 -88
app.R CHANGED
@@ -1,88 +1,88 @@
1
- #
2
- # This is a Shiny web application. You can run the application by clicking
3
- # the 'Run App' button above.
4
- #
5
- # Find out more about building applications with Shiny here:
6
- #
7
- # https://shiny.posit.co/
8
- #
9
-
10
- library(shiny)
11
- library(dplyr)
12
- library(data.table)
13
- library(xgboost)
14
- library(caret)
15
- # Define UI for application that draws a histogram
16
- ui <- fluidPage(
17
-
18
- # Application title
19
- titlePanel("TimStuff Fastball Calculator"),
20
-
21
- # Sidebar with a slider input for number of bins
22
- sidebarLayout(
23
- sidebarPanel(
24
- selectInput("phand",
25
- "Hand",
26
- c("R","L")),
27
- numericInput("velo",
28
- "Velocity /mph",90),
29
- numericInput("ivb",
30
- "Induced Vertical Break (IVB) /in. (IVB)",16),
31
- numericInput("hb",
32
- "Horizontal Break (HB) /in. (Pitcher's Perspective)",6),
33
- numericInput("spinrate",
34
- "Spin Rate /rpm",2300),
35
- numericInput("ext",
36
- "Extension /ft",6),
37
- numericInput("spinaxisdiff",
38
- "Spin Axis Difference (-180 - 180) /degrees",0),
39
- numericInput("x0","Horizntal Release Point /ft. (Batter's Perspective)",0),
40
- numericInput("z0","Vertical Release Point /ft. (Batter's Perspective)", 0),
41
-
42
-
43
- ),
44
-
45
- # Show a plot of the generated distribution
46
- mainPanel(
47
- textOutput("distPlot")
48
- )
49
- )
50
- )
51
-
52
- # Define server logic required to draw a histogram
53
- server <- function(input, output) {
54
-
55
- output$distPlot <- renderText({
56
- data <- as.data.frame(5)
57
- setnames(data,"5","start_speed")
58
- data$start_speed <- input$velo
59
- data$IVB <- input$ivb
60
- if(input$phand == "L"){
61
- data$HB <- input$hb * -1
62
- }
63
- else{
64
- data$HB <- input$hb
65
- }
66
- data$EAA <- input$ext / 6.3
67
- if(input$phand == "L"){
68
- data$x0 <- input$x0 * -1
69
- }
70
- else{
71
- data$x0 <- input$x0
72
- }
73
- data$z0 <- input$z0
74
- data$spin_rate <- input$spinrate
75
- data$SADiff <- input$spinaxisdiff
76
-
77
- data <- as.matrix(data)
78
-
79
- prediction <-predict(FBMod,data)
80
- TimStuff <- (50 - (prediction - -0.0004397118)/ 0.2180433 * 10)
81
- # FBMod <- xgb.load("FB.model")
82
- # vip(FBMod)
83
- return(TimStuff)
84
- })
85
- }
86
-
87
- # Run the application
88
- shinyApp(ui = ui, server = server)
 
1
+ #
2
+ # This is a Shiny web application. You can run the application by clicking
3
+ # the 'Run App' button above.
4
+ #
5
+ # Find out more about building applications with Shiny here:
6
+ #
7
+ # https://shiny.posit.co/
8
+ #
9
+
10
+ library(shiny)
11
+ library(dplyr)
12
+ library(data.table)
13
+ library(xgboost)
14
+ library(caret)
15
+ # Define UI for application that draws a histogram
16
+ ui <- fluidPage(
17
+
18
+ # Application title
19
+ titlePanel("TimStuff Fastball Calculator"),
20
+
21
+ # Sidebar with a slider input for number of bins
22
+ sidebarLayout(
23
+ sidebarPanel(
24
+ selectInput("phand",
25
+ "Hand",
26
+ c("R","L")),
27
+ numericInput("velo",
28
+ "Velocity /mph",90),
29
+ numericInput("ivb",
30
+ "Induced Vertical Break (IVB) /in. (IVB)",16),
31
+ numericInput("hb",
32
+ "Horizontal Break (HB) /in. (Pitcher's Perspective)",6),
33
+ numericInput("spinrate",
34
+ "Spin Rate /rpm",2300),
35
+ numericInput("ext",
36
+ "Extension /ft",6),
37
+ numericInput("spinaxisdiff",
38
+ "Spin Axis Difference (-180 - 180) /degrees",0),
39
+ numericInput("x0","Horizntal Release Point /ft. (Batter's Perspective)",0),
40
+ numericInput("z0","Vertical Release Point /ft. (Batter's Perspective)", 0),
41
+
42
+
43
+ ),
44
+
45
+ # Show a plot of the generated distribution
46
+ mainPanel(
47
+ textOutput("distPlot")
48
+ )
49
+ )
50
+ )
51
+
52
+ # Define server logic required to draw a histogram
53
+ server <- function(input, output) {
54
+
55
+ output$distPlot <- renderText({
56
+ data <- as.data.frame(5)
57
+ setnames(data,"5","start_speed")
58
+ data$start_speed <- input$velo
59
+ data$IVB <- input$ivb
60
+ if(input$phand == "L"){
61
+ data$HB <- input$hb * -1
62
+ }
63
+ else{
64
+ data$HB <- input$hb
65
+ }
66
+ data$EAA <- input$ext / 6.3
67
+ if(input$phand == "L"){
68
+ data$x0 <- input$x0 * -1
69
+ }
70
+ else{
71
+ data$x0 <- input$x0
72
+ }
73
+ data$z0 <- input$z0
74
+ data$spin_rate <- input$spinrate
75
+ data$SADiff <- input$spinaxisdiff
76
+
77
+ data <- as.matrix(data)
78
+ FBMod <- xgb.load('FB.Model')
79
+ prediction <-predict(FBMod,data)
80
+ TimStuff <- (50 - (prediction - -0.0004397118)/ 0.2180433 * 10)
81
+ # FBMod <- xgb.load("FB.model")
82
+ # vip(FBMod)
83
+ return(TimStuff)
84
+ })
85
+ }
86
+
87
+ # Run the application
88
+ shinyApp(ui = ui, server = server)