Spaces:
Runtime error
Runtime error
| # | |
| # This is a Shiny web application. You can run the application by clicking | |
| # the 'Run App' button above. | |
| # | |
| # Find out more about building applications with Shiny here: | |
| # | |
| # https://shiny.posit.co/ | |
| # | |
| library(shiny) | |
| library(dplyr) | |
| library(data.table) | |
| library(xgboost) | |
| library(caret) | |
| # Define UI for application that draws a histogram | |
| ui <- fluidPage( | |
| # Application title | |
| titlePanel("TimStuff Fastball Calculator"), | |
| # Sidebar with a slider input for number of bins | |
| sidebarLayout( | |
| sidebarPanel( | |
| selectInput("phand", | |
| "Hand", | |
| c("R","L")), | |
| numericInput("velo", | |
| "Velocity /mph",90), | |
| numericInput("ivb", | |
| "Induced Vertical Break (IVB) /in. (IVB)",16), | |
| numericInput("hb", | |
| "Horizontal Break (HB) /in. (Pitcher's Perspective)",6), | |
| numericInput("spinrate", | |
| "Spin Rate /rpm",2300), | |
| numericInput("ext", | |
| "Extension /ft",6), | |
| numericInput("spinaxisdiff", | |
| "Spin Axis Difference (-180 - 180) /degrees",0), | |
| numericInput("x0","Horizntal Release Point /ft. (Batter's Perspective)",0), | |
| numericInput("z0","Vertical Release Point /ft. (Batter's Perspective)", 0), | |
| ), | |
| # Show a plot of the generated distribution | |
| mainPanel( | |
| textOutput("distPlot") | |
| ) | |
| ) | |
| ) | |
| # Define server logic required to draw a histogram | |
| server <- function(input, output) { | |
| output$distPlot <- renderText({ | |
| data <- as.data.frame(5) | |
| setnames(data,"5","start_speed") | |
| data$start_speed <- input$velo | |
| data$IVB <- input$ivb | |
| if(input$phand == "L"){ | |
| data$HB <- input$hb * -1 | |
| } | |
| else{ | |
| data$HB <- input$hb | |
| } | |
| data$EAA <- input$ext / 6.3 | |
| if(input$phand == "L"){ | |
| data$x0 <- input$x0 * -1 | |
| } | |
| else{ | |
| data$x0 <- input$x0 | |
| } | |
| data$z0 <- input$z0 | |
| data$spin_rate <- input$spinrate | |
| data$SADiff <- input$spinaxisdiff | |
| data <- as.matrix(data) | |
| FBMod <- xgb.load('FB.Model') | |
| prediction <-predict(FBMod,data) | |
| TimStuff <- (50 - (prediction - -0.0004397118)/ 0.2180433 * 10) | |
| # FBMod <- xgb.load("FB.model") | |
| # vip(FBMod) | |
| return(TimStuff) | |
| }) | |
| } | |
| # Run the application | |
| shinyApp(ui = ui, server = server) | |