Update app.R
Browse files
app.R
CHANGED
|
@@ -3,11 +3,9 @@ library(gt)
|
|
| 3 |
library(dplyr)
|
| 4 |
library(shinyjs)
|
| 5 |
library(shinyauthr)
|
| 6 |
-
|
| 7 |
-
library(httr)
|
| 8 |
library(bslib)
|
| 9 |
-
|
| 10 |
-
#Beam <- read.csv('Beam.csv')
|
| 11 |
|
| 12 |
download_private_csv <- function(repo_id, filename) {
|
| 13 |
url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename)
|
|
@@ -19,10 +17,10 @@ download_private_csv <- function(repo_id, filename) {
|
|
| 19 |
|
| 20 |
# Try different read options
|
| 21 |
data <- read.csv(con,
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
close(con)
|
| 27 |
return(data)
|
| 28 |
} else {
|
|
@@ -31,6 +29,8 @@ download_private_csv <- function(repo_id, filename) {
|
|
| 31 |
}
|
| 32 |
|
| 33 |
Beam <- download_private_csv("TimStats/CollegePriv", "Beam.csv")
|
|
|
|
|
|
|
| 34 |
|
| 35 |
test <- Beam %>%
|
| 36 |
select(Date,PitchofPA,Pitcher,PitcherId,PitcherThrows,PitcherTeam,Batter,BatterId,
|
|
@@ -74,6 +74,11 @@ test <- test %>%
|
|
| 74 |
"AB" = Strikeout + BIP - Sac,
|
| 75 |
"PA" = Strikeout + BIP + Walk + HBP
|
| 76 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
gt_theme_tim <- function(gt_object,...) {
|
|
@@ -159,51 +164,118 @@ gt_theme_tim <- function(gt_object,...) {
|
|
| 159 |
}
|
| 160 |
|
| 161 |
user_base <- tibble::tibble(
|
| 162 |
-
user = c(
|
| 163 |
-
password = c(
|
| 164 |
-
permissions = c("admin"),
|
| 165 |
-
name = c("User One")
|
| 166 |
)
|
| 167 |
|
| 168 |
# Define UI for application that draws a histogram
|
| 169 |
ui <- fluidPage(
|
| 170 |
-
div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
div(
|
| 176 |
id = "bar",
|
| 177 |
-
|
| 178 |
-
titlePanel("College Pitcher"),
|
| 179 |
-
|
| 180 |
-
# Sidebar layout
|
| 181 |
-
sidebarLayout(
|
| 182 |
-
sidebarPanel(
|
| 183 |
-
selectInput("player",
|
| 184 |
-
"Select Player",
|
| 185 |
-
choices = unique(test$Pitcher)),
|
| 186 |
-
width = 3
|
| 187 |
-
),
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
gt_output("InningFilter"),
|
| 196 |
-
gt_output("SideFilter")
|
| 197 |
-
)
|
| 198 |
),
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
)
|
| 201 |
-
)
|
| 202 |
) %>% shinyjs::hidden()
|
| 203 |
)
|
| 204 |
|
| 205 |
-
#
|
| 206 |
-
server <- function(input, output) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
credentials <- shinyauthr::loginServer(
|
| 209 |
id = "login",
|
|
@@ -227,284 +299,580 @@ server <- function(input, output) {
|
|
| 227 |
shinyjs::hide(id = "bar")
|
| 228 |
}
|
| 229 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
|
|
|
| 255 |
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
)
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
)
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
)
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
}
|
| 509 |
|
| 510 |
# Run the application
|
|
|
|
| 3 |
library(dplyr)
|
| 4 |
library(shinyjs)
|
| 5 |
library(shinyauthr)
|
| 6 |
+
library(gtExtras)
|
|
|
|
| 7 |
library(bslib)
|
| 8 |
+
library(baseballr)
|
|
|
|
| 9 |
|
| 10 |
download_private_csv <- function(repo_id, filename) {
|
| 11 |
url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename)
|
|
|
|
| 17 |
|
| 18 |
# Try different read options
|
| 19 |
data <- read.csv(con,
|
| 20 |
+
header = TRUE,
|
| 21 |
+
check.names = FALSE, # This prevents R from modifying column names
|
| 22 |
+
fileEncoding = "UTF-8",
|
| 23 |
+
stringsAsFactors = FALSE)
|
| 24 |
close(con)
|
| 25 |
return(data)
|
| 26 |
} else {
|
|
|
|
| 29 |
}
|
| 30 |
|
| 31 |
Beam <- download_private_csv("TimStats/CollegePriv", "Beam.csv")
|
| 32 |
+
Beam <- download_private_csv("TimStats/TMP", "Beam.csv")
|
| 33 |
+
Beam <- download_private_csv("TimStats/RMB", "Beam.csv")
|
| 34 |
|
| 35 |
test <- Beam %>%
|
| 36 |
select(Date,PitchofPA,Pitcher,PitcherId,PitcherThrows,PitcherTeam,Batter,BatterId,
|
|
|
|
| 74 |
"AB" = Strikeout + BIP - Sac,
|
| 75 |
"PA" = Strikeout + BIP + Walk + HBP
|
| 76 |
)
|
| 77 |
+
test <- test %>%
|
| 78 |
+
left_join(TMB, by = c(BatterTeam = "team_abbr")) %>%
|
| 79 |
+
left_join(TMP, by = c(PitcherTeam = "team_abbr")) %>%
|
| 80 |
+
mutate(PitcherAndTeam = paste0(Pitcher," - ",PTeamName)) %>%
|
| 81 |
+
mutate(BatterAndTeam = paste0(Batter," - ",BTeamName))
|
| 82 |
|
| 83 |
|
| 84 |
gt_theme_tim <- function(gt_object,...) {
|
|
|
|
| 164 |
}
|
| 165 |
|
| 166 |
user_base <- tibble::tibble(
|
| 167 |
+
user = c("TrentR", "TimChen"),
|
| 168 |
+
password = (c("Caprisun", "TimStats")),
|
| 169 |
+
permissions = c("admin", "standard"),
|
| 170 |
+
name = c("User One", "User Two")
|
| 171 |
)
|
| 172 |
|
| 173 |
# Define UI for application that draws a histogram
|
| 174 |
ui <- fluidPage(
|
|
|
|
| 175 |
|
| 176 |
+
tags$head(
|
| 177 |
+
tags$style(
|
| 178 |
+
HTML("
|
| 179 |
+
.shiny-output-error { visibility: hidden; }
|
| 180 |
+
.shiny-output-error:before { visibility: hidden; }
|
| 181 |
+
")
|
| 182 |
+
)
|
| 183 |
+
),
|
| 184 |
|
| 185 |
+
# Rest of your existing UI code stays exactly the same
|
| 186 |
+
div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
|
| 187 |
+
# div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
|
| 188 |
+
#
|
| 189 |
+
# shinyauthr::loginUI(id = "login"),
|
| 190 |
+
#
|
| 191 |
div(
|
| 192 |
id = "bar",
|
| 193 |
+
titlePanel("TimMedia"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
+
sidebarLayout(
|
| 196 |
+
sidebarPanel(
|
| 197 |
+
uiOutput("dynamicSelect"), # Replace selectInput with uiOutput
|
| 198 |
+
dateRangeInput("date","Date Range:",start = "2024-01-01"),
|
| 199 |
+
imageOutput("teamLogo", height = "150px"),
|
| 200 |
+
width = 3
|
|
|
|
|
|
|
|
|
|
| 201 |
),
|
| 202 |
+
|
| 203 |
+
mainPanel(
|
| 204 |
+
tabsetPanel(id = "tabs", # Add id here
|
| 205 |
+
tabPanel("Pitcher Splits",
|
| 206 |
+
gt_output("CountFilterP"),
|
| 207 |
+
gt_output("PitchFilterP"),
|
| 208 |
+
gt_output("PitchSideFilterP"),
|
| 209 |
+
gt_output("InningFilterP"),
|
| 210 |
+
gt_output("SideFilterP")
|
| 211 |
+
),
|
| 212 |
+
tabPanel("Batter Splits",
|
| 213 |
+
gt_output("CountFilterB"),
|
| 214 |
+
gt_output("PitchFilterB"),
|
| 215 |
+
gt_output("PitchSideFilterB"),
|
| 216 |
+
gt_output("InningFilterB"),
|
| 217 |
+
gt_output("SideFilterB")
|
| 218 |
+
)
|
| 219 |
+
),
|
| 220 |
+
width = 9
|
| 221 |
+
)
|
| 222 |
)
|
|
|
|
| 223 |
) %>% shinyjs::hidden()
|
| 224 |
)
|
| 225 |
|
| 226 |
+
# Then in the server, add these new reactive elements:
|
| 227 |
+
server <- function(input, output, session) {
|
| 228 |
+
options(shiny.sanitize.errors = TRUE)
|
| 229 |
+
|
| 230 |
+
# Add this reactive element
|
| 231 |
+
playerType <- reactive({
|
| 232 |
+
if(input$tabs == "Pitcher Splits") {
|
| 233 |
+
list(
|
| 234 |
+
choices = unique(test$PitcherAndTeam),
|
| 235 |
+
selected = NULL,
|
| 236 |
+
logo_column = "PTeamLogo",
|
| 237 |
+
filter_column = "PitcherAndTeam"
|
| 238 |
+
)
|
| 239 |
+
} else {
|
| 240 |
+
list(
|
| 241 |
+
choices = unique(test$BatterAndTeam),
|
| 242 |
+
selected = NULL,
|
| 243 |
+
logo_column = "BTeamLogo",
|
| 244 |
+
filter_column = "BatterAndTeam"
|
| 245 |
+
)
|
| 246 |
+
}
|
| 247 |
+
})
|
| 248 |
+
|
| 249 |
+
# Create dynamic select input
|
| 250 |
+
output$dynamicSelect <- renderUI({
|
| 251 |
+
selectInput("player",
|
| 252 |
+
"Select Player",
|
| 253 |
+
choices = playerType()$choices)
|
| 254 |
+
})
|
| 255 |
+
|
| 256 |
+
# Modify the team logo render
|
| 257 |
+
output$teamLogo <- renderImage({
|
| 258 |
+
req(input$player)
|
| 259 |
+
|
| 260 |
+
selected_logo <- test %>%
|
| 261 |
+
filter(!!sym(playerType()$filter_column) == input$player) %>%
|
| 262 |
+
slice(1) %>%
|
| 263 |
+
pull(!!sym(playerType()$logo_column))
|
| 264 |
+
|
| 265 |
+
temp_file <- tempfile(fileext = ".png")
|
| 266 |
+
download.file(selected_logo, temp_file, mode = "wb")
|
| 267 |
+
|
| 268 |
+
list(
|
| 269 |
+
src = temp_file,
|
| 270 |
+
contentType = "image/png",
|
| 271 |
+
width = "150px",
|
| 272 |
+
height = "150px",
|
| 273 |
+
alt = "Team Logo",
|
| 274 |
+
deleteFile = TRUE,
|
| 275 |
+
style = "display: block; margin: auto;"
|
| 276 |
+
)
|
| 277 |
+
}, deleteFile = TRUE)
|
| 278 |
+
|
| 279 |
|
| 280 |
credentials <- shinyauthr::loginServer(
|
| 281 |
id = "login",
|
|
|
|
| 299 |
shinyjs::hide(id = "bar")
|
| 300 |
}
|
| 301 |
})
|
| 302 |
+
# observeEvent(input$date,{
|
| 303 |
+
# test <- test %>% filter(between(as.Date(Date),input$date[1],input$date[2]))
|
| 304 |
+
# })
|
| 305 |
+
|
| 306 |
+
output$CountFilterP <- render_gt({
|
| 307 |
+
test <- test %>% filter(PitcherAndTeam == input$player) %>% group_by(Count) %>%
|
| 308 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 309 |
+
summarise(
|
| 310 |
+
Pitches = n(),
|
| 311 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 312 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 313 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 314 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 315 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 316 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 317 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 318 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 319 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 320 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 321 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 322 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 323 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 324 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 325 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 326 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 327 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 328 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 329 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 330 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 331 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 332 |
+
ungroup()%>%
|
| 333 |
+
gt() %>%
|
| 334 |
+
gt_theme_tim() %>%
|
| 335 |
+
fmt_number(columns = `Avg EV`:`Max EV`,decimals = 1) %>%
|
| 336 |
+
cols_width(Count:Pitches ~ px(70),
|
| 337 |
+
everything() ~ px(85)) %>%
|
| 338 |
+
cols_align(align = "center") %>%
|
| 339 |
+
fmt_number(columns = AVG:SLG,decimals = 3) %>%
|
| 340 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 341 |
+
sub_missing() %>%
|
| 342 |
+
#gt_theme_savant() %>%
|
| 343 |
+
opt_interactive(
|
| 344 |
+
use_compact_mode = TRUE,
|
| 345 |
+
use_pagination = FALSE
|
| 346 |
+
)
|
| 347 |
+
})
|
| 348 |
+
output$PitchFilterP <- render_gt({
|
| 349 |
+
tes <- test %>%
|
| 350 |
+
filter(PitcherAndTeam == input$player) %>%
|
| 351 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 352 |
+
group_by(AutoPitchType) %>%
|
| 353 |
+
summarise(
|
| 354 |
+
Pitches = n(),
|
| 355 |
+
# BBE = sum(BBE,na.rm = TRUE),
|
| 356 |
+
"Usage%" = n() / nrow(.), # Added Usage% calculation
|
| 357 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 358 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 359 |
+
"CSW%" = mean(CSW, na.rm = TRUE),
|
| 360 |
+
"Zone%" = mean(Zone, na.rm = TRUE),
|
| 361 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE], na.rm = TRUE),
|
| 362 |
+
"ZSwing%" = mean(Swing[Zone == TRUE], na.rm = TRUE),
|
| 363 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE], na.rm = TRUE),
|
| 364 |
+
"OSwing%" = mean(Swing[Zone == FALSE], na.rm = TRUE),
|
| 365 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 366 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE], .9, na.rm = TRUE),
|
| 367 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 368 |
+
"Max EV" = ifelse(is.infinite(`Max EV`), NA, `Max EV`),
|
| 369 |
+
"GB%" = mean(GB[BBE == TRUE], na.rm = TRUE),
|
| 370 |
+
"LD%" = mean(LD[BBE == TRUE], na.rm = TRUE),
|
| 371 |
+
"FB%" = mean(FB[BBE == TRUE], na.rm = TRUE),
|
| 372 |
+
"AVG" = round(sum(Hit, na.rm = TRUE) / sum(AB, na.rm = TRUE), digits = 3),
|
| 373 |
+
"OBP" = round((sum(Hit, na.rm = TRUE) + sum(Walk, na.rm = TRUE) + sum(HBP, na.rm = TRUE)) /
|
| 374 |
+
sum(PA, na.rm = TRUE), digits = 3),
|
| 375 |
+
"SLG" = (round(sum(Single, na.rm = TRUE) + sum(Double, na.rm = TRUE) * 2 +
|
| 376 |
+
sum(Triple, na.rm = TRUE) * 3 + sum(HR, na.rm = TRUE))) / sum(AB, na.rm = TRUE)
|
| 377 |
+
) %>%
|
| 378 |
+
ungroup() %>%
|
| 379 |
+
arrange(desc(Pitches)) %>%
|
| 380 |
+
gt() %>%
|
| 381 |
+
gt_theme_tim() %>%
|
| 382 |
+
fmt_number(columns = `Avg EV`:`Max EV`, decimals = 1) %>%
|
| 383 |
+
cols_label(AutoPitchType = "Type") %>%
|
| 384 |
+
cols_width(
|
| 385 |
+
AutoPitchType ~ px(100),
|
| 386 |
+
Pitches ~ px(70),
|
| 387 |
+
everything() ~ px(85)
|
| 388 |
+
) %>%
|
| 389 |
+
cols_align(align = "center") %>%
|
| 390 |
+
fmt_number(columns = AVG:SLG, decimals = 3) %>%
|
| 391 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 392 |
+
sub_missing() %>%
|
| 393 |
+
opt_interactive(
|
| 394 |
+
use_compact_mode = TRUE,
|
| 395 |
+
use_pagination = FALSE
|
| 396 |
+
)
|
| 397 |
+
})
|
| 398 |
+
output$PitchSideFilterP <- render_gt({
|
| 399 |
+
test <- test %>%
|
| 400 |
+
filter(PitcherAndTeam == input$player) %>%
|
| 401 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 402 |
+
group_by(BatterSide) %>%
|
| 403 |
+
mutate(total_side = n()) %>%
|
| 404 |
+
ungroup() %>%
|
| 405 |
+
group_by(AutoPitchType, BatterSide) %>%
|
| 406 |
+
summarise(
|
| 407 |
+
Pitches = n(),
|
| 408 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 409 |
+
"Usage%" = (n() / first(total_side)),
|
| 410 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 411 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 412 |
+
"CSW%" = mean(CSW, na.rm = TRUE),
|
| 413 |
+
"Zone%" = mean(Zone, na.rm = TRUE),
|
| 414 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE], na.rm = TRUE),
|
| 415 |
+
"ZSwing%" = mean(Swing[Zone == TRUE], na.rm = TRUE),
|
| 416 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE], na.rm = TRUE),
|
| 417 |
+
"OSwing%" = mean(Swing[Zone == FALSE], na.rm = TRUE),
|
| 418 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 419 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE], .9, na.rm = TRUE),
|
| 420 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 421 |
+
"Max EV" = ifelse(is.infinite(`Max EV`), NA, `Max EV`),
|
| 422 |
+
"GB%" = mean(GB[BBE == TRUE], na.rm = TRUE),
|
| 423 |
+
"LD%" = mean(LD[BBE == TRUE], na.rm = TRUE),
|
| 424 |
+
"FB%" = mean(FB[BBE == TRUE], na.rm = TRUE),
|
| 425 |
+
"AVG" = round(sum(Hit, na.rm = TRUE) / sum(AB, na.rm = TRUE), digits = 3),
|
| 426 |
+
"OBP" = round((sum(Hit, na.rm = TRUE) + sum(Walk, na.rm = TRUE) + sum(HBP, na.rm = TRUE)) /
|
| 427 |
+
sum(PA, na.rm = TRUE), digits = 3),
|
| 428 |
+
"SLG" = (round(sum(Single, na.rm = TRUE) + sum(Double, na.rm = TRUE) * 2 +
|
| 429 |
+
sum(Triple, na.rm = TRUE) * 3 + sum(HR, na.rm = TRUE))) / sum(AB, na.rm = TRUE)
|
| 430 |
+
) %>%
|
| 431 |
+
ungroup() %>%
|
| 432 |
+
arrange(desc(BatterSide),desc(Pitches)) %>%
|
| 433 |
+
gt() %>%
|
| 434 |
+
gt_theme_tim() %>%
|
| 435 |
+
fmt_number(columns = `Avg EV`:`Max EV`, decimals = 1) %>%
|
| 436 |
+
cols_label(AutoPitchType = "Type", BatterSide = "Side") %>%
|
| 437 |
+
cols_width(
|
| 438 |
+
AutoPitchType ~ px(100),
|
| 439 |
+
Pitches ~ px(70),
|
| 440 |
+
BatterSide ~ px(70),
|
| 441 |
+
everything() ~ px(85)
|
| 442 |
+
) %>%
|
| 443 |
+
cols_align(align = "center") %>%
|
| 444 |
+
fmt_number(columns = AVG:SLG, decimals = 3) %>%
|
| 445 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 446 |
+
sub_missing() %>%
|
| 447 |
+
opt_interactive(
|
| 448 |
+
use_compact_mode = TRUE,
|
| 449 |
+
use_pagination = FALSE
|
| 450 |
+
)
|
| 451 |
+
})
|
| 452 |
+
output$InningFilterP <- render_gt({
|
| 453 |
+
test <- test %>% filter(PitcherAndTeam == input$player) %>% group_by(Inning) %>%
|
| 454 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 455 |
+
summarise(
|
| 456 |
+
Pitches = n(),
|
| 457 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 458 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 459 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 460 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 461 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 462 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 463 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 464 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 465 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 466 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 467 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 468 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 469 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 470 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 471 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 472 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 473 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 474 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 475 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 476 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 477 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 478 |
+
ungroup()%>%
|
| 479 |
+
gt() %>%
|
| 480 |
+
gt_theme_tim() %>%
|
| 481 |
+
fmt_number(columns = `Avg EV`:`Max EV`,decimals = 1) %>%
|
| 482 |
+
cols_width(Inning:Pitches ~ px(70),
|
| 483 |
+
everything() ~ px(85)) %>%
|
| 484 |
+
cols_align(align = "center") %>%
|
| 485 |
+
fmt_number(columns = AVG:SLG,decimals = 3) %>%
|
| 486 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 487 |
+
sub_missing() %>%
|
| 488 |
+
#gt_theme_savant() %>%
|
| 489 |
+
opt_interactive(
|
| 490 |
+
use_compact_mode = TRUE,
|
| 491 |
+
use_pagination = FALSE
|
| 492 |
+
)
|
| 493 |
+
})
|
| 494 |
+
output$SideFilterP <- render_gt({
|
| 495 |
+
test1 <- test %>% filter(PitcherAndTeam == input$player) %>% group_by(BatterSide) %>%
|
| 496 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 497 |
+
summarise(
|
| 498 |
+
Pitches = n(),
|
| 499 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 500 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 501 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 502 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 503 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 504 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 505 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 506 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 507 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 508 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 509 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 510 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 511 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 512 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 513 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 514 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 515 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 516 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 517 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 518 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 519 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 520 |
+
ungroup()
|
| 521 |
+
test2 <- test %>% mutate(BatterSide = "Both") %>% filter(PitcherAndTeam == input$player) %>% group_by(BatterSide) %>%
|
| 522 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 523 |
+
summarise(
|
| 524 |
+
Pitches = n(),
|
| 525 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 526 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 527 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 528 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 529 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 530 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 531 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 532 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 533 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 534 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 535 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 536 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 537 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 538 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 539 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 540 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 541 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 542 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 543 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 544 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 545 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 546 |
+
ungroup()
|
| 547 |
+
test <- rbind(test1,test2)
|
| 548 |
+
test %>%
|
| 549 |
+
gt() %>%
|
| 550 |
+
gt_theme_tim() %>%
|
| 551 |
+
fmt_number(columns = `Avg EV`:`Max EV`,decimals = 1) %>%
|
| 552 |
+
cols_width(BatterSide:Pitches ~ px(70),
|
| 553 |
+
everything() ~ px(85)) %>%
|
| 554 |
+
cols_align(align = "center") %>%
|
| 555 |
+
cols_label(BatterSide = "Side") %>%
|
| 556 |
+
fmt_number(columns = AVG:SLG,decimals = 3) %>%
|
| 557 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 558 |
+
sub_missing() %>%
|
| 559 |
+
#gt_theme_savant() %>%
|
| 560 |
+
opt_interactive(
|
| 561 |
+
use_compact_mode = TRUE,
|
| 562 |
+
use_pagination = FALSE
|
| 563 |
+
)
|
| 564 |
+
|
| 565 |
+
})
|
| 566 |
+
output$slashlineP <- render_gt({
|
| 567 |
+
test <- test %>% filter(PitcherAndTeam == input$player) %>%
|
| 568 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 569 |
+
summarise(
|
| 570 |
+
Pitches = n(),
|
| 571 |
+
`1B` = sum(Single,na.rm = TRUE),
|
| 572 |
+
`2B` = sum(Double,na.rm = TRUE),
|
| 573 |
+
`3B` = sum(Triple,na.rm = TRUE),
|
| 574 |
+
HR = sum(HR,na.rm = TRUE),
|
| 575 |
+
SO = sum(Strikeout,na.rm = TRUE),
|
| 576 |
+
BB = sum(Walk,na.rm = TRUE),
|
| 577 |
+
Whiffs = sum(Whiff,na.rm = TRUE),
|
| 578 |
+
`Hard Hits` = sum(HardHit,na.rm = TRUE)
|
| 579 |
+
)%>%
|
| 580 |
+
ungroup()%>%
|
| 581 |
+
gt() %>%
|
| 582 |
+
gt_theme_tim() %>%
|
| 583 |
+
cols_align(align = "center") %>%
|
| 584 |
+
# gt_theme_savant() %>%
|
| 585 |
+
opt_interactive(
|
| 586 |
+
use_compact_mode = TRUE,
|
| 587 |
+
use_pagination = FALSE
|
| 588 |
+
)
|
| 589 |
+
})
|
| 590 |
|
| 591 |
+
output$CountFilterB <- render_gt({
|
| 592 |
+
test <- test %>% filter(BatterAndTeam == input$player) %>% group_by(Count) %>%
|
| 593 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 594 |
+
summarise(
|
| 595 |
+
Pitches = n(),
|
| 596 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 597 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 598 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 599 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 600 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 601 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 602 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 603 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 604 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 605 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 606 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 607 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 608 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 609 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 610 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 611 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 612 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 613 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 614 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 615 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 616 |
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 617 |
+
ungroup()%>%
|
| 618 |
+
gt() %>%
|
| 619 |
+
gt_theme_tim() %>%
|
| 620 |
+
fmt_number(columns = `Avg EV`:`Max EV`,decimals = 1) %>%
|
| 621 |
+
cols_width(Count:Pitches ~ px(70),
|
| 622 |
+
everything() ~ px(85)) %>%
|
| 623 |
+
cols_align(align = "center") %>%
|
| 624 |
+
fmt_number(columns = AVG:SLG,decimals = 3) %>%
|
| 625 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 626 |
+
sub_missing() %>%
|
| 627 |
+
#gt_theme_savant() %>%
|
| 628 |
+
opt_interactive(
|
| 629 |
+
use_compact_mode = TRUE,
|
| 630 |
+
use_pagination = FALSE
|
| 631 |
+
)
|
| 632 |
+
})
|
| 633 |
+
output$PitchFilterB <- render_gt({
|
| 634 |
+
tes <- test %>%
|
| 635 |
+
filter(BatterAndTeam == input$player) %>%
|
| 636 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 637 |
+
group_by(AutoPitchType) %>%
|
| 638 |
+
summarise(
|
| 639 |
+
Pitches = n(),
|
| 640 |
+
# BBE = sum(BBE,na.rm = TRUE),
|
| 641 |
+
"Pitch%" = n() / nrow(.), # Added Pitch% calculation
|
| 642 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 643 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 644 |
+
"CSW%" = mean(CSW, na.rm = TRUE),
|
| 645 |
+
"Zone%" = mean(Zone, na.rm = TRUE),
|
| 646 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE], na.rm = TRUE),
|
| 647 |
+
"ZSwing%" = mean(Swing[Zone == TRUE], na.rm = TRUE),
|
| 648 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE], na.rm = TRUE),
|
| 649 |
+
"OSwing%" = mean(Swing[Zone == FALSE], na.rm = TRUE),
|
| 650 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 651 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE], .9, na.rm = TRUE),
|
| 652 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 653 |
+
"Max EV" = ifelse(is.infinite(`Max EV`), NA, `Max EV`),
|
| 654 |
+
"GB%" = mean(GB[BBE == TRUE], na.rm = TRUE),
|
| 655 |
+
"LD%" = mean(LD[BBE == TRUE], na.rm = TRUE),
|
| 656 |
+
"FB%" = mean(FB[BBE == TRUE], na.rm = TRUE),
|
| 657 |
+
"AVG" = round(sum(Hit, na.rm = TRUE) / sum(AB, na.rm = TRUE), digits = 3),
|
| 658 |
+
"OBP" = round((sum(Hit, na.rm = TRUE) + sum(Walk, na.rm = TRUE) + sum(HBP, na.rm = TRUE)) /
|
| 659 |
+
sum(PA, na.rm = TRUE), digits = 3),
|
| 660 |
+
"SLG" = (round(sum(Single, na.rm = TRUE) + sum(Double, na.rm = TRUE) * 2 +
|
| 661 |
+
sum(Triple, na.rm = TRUE) * 3 + sum(HR, na.rm = TRUE))) / sum(AB, na.rm = TRUE)
|
| 662 |
+
) %>%
|
| 663 |
+
ungroup() %>%
|
| 664 |
+
arrange(desc(Pitches)) %>%
|
| 665 |
+
gt() %>%
|
| 666 |
+
gt_theme_tim() %>%
|
| 667 |
+
fmt_number(columns = `Avg EV`:`Max EV`, decimals = 1) %>%
|
| 668 |
+
cols_label(AutoPitchType = "Type") %>%
|
| 669 |
+
cols_width(
|
| 670 |
+
AutoPitchType ~ px(100),
|
| 671 |
+
Pitches ~ px(70),
|
| 672 |
+
everything() ~ px(85)
|
| 673 |
+
) %>%
|
| 674 |
+
cols_align(align = "center") %>%
|
| 675 |
+
fmt_number(columns = AVG:SLG, decimals = 3) %>%
|
| 676 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 677 |
+
sub_missing() %>%
|
| 678 |
+
opt_interactive(
|
| 679 |
+
use_compact_mode = TRUE,
|
| 680 |
+
use_pagination = FALSE
|
| 681 |
+
)
|
| 682 |
+
})
|
| 683 |
+
output$PitchSideFilterB <- render_gt({
|
| 684 |
+
test <- test %>%
|
| 685 |
+
filter(BatterAndTeam == input$player) %>%
|
| 686 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 687 |
+
group_by(PitcherThrows) %>%
|
| 688 |
+
mutate(total_side = n()) %>%
|
| 689 |
+
ungroup() %>%
|
| 690 |
+
group_by(AutoPitchType, PitcherThrows) %>%
|
| 691 |
+
summarise(
|
| 692 |
+
Pitches = n(),
|
| 693 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 694 |
+
"Pitch%" = (n() / first(total_side)),
|
| 695 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 696 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 697 |
+
"CSW%" = mean(CSW, na.rm = TRUE),
|
| 698 |
+
"Zone%" = mean(Zone, na.rm = TRUE),
|
| 699 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE], na.rm = TRUE),
|
| 700 |
+
"ZSwing%" = mean(Swing[Zone == TRUE], na.rm = TRUE),
|
| 701 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE], na.rm = TRUE),
|
| 702 |
+
"OSwing%" = mean(Swing[Zone == FALSE], na.rm = TRUE),
|
| 703 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 704 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE], .9, na.rm = TRUE),
|
| 705 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE], na.rm = TRUE),
|
| 706 |
+
"Max EV" = ifelse(is.infinite(`Max EV`), NA, `Max EV`),
|
| 707 |
+
"GB%" = mean(GB[BBE == TRUE], na.rm = TRUE),
|
| 708 |
+
"LD%" = mean(LD[BBE == TRUE], na.rm = TRUE),
|
| 709 |
+
"FB%" = mean(FB[BBE == TRUE], na.rm = TRUE),
|
| 710 |
+
"AVG" = round(sum(Hit, na.rm = TRUE) / sum(AB, na.rm = TRUE), digits = 3),
|
| 711 |
+
"OBP" = round((sum(Hit, na.rm = TRUE) + sum(Walk, na.rm = TRUE) + sum(HBP, na.rm = TRUE)) /
|
| 712 |
+
sum(PA, na.rm = TRUE), digits = 3),
|
| 713 |
+
"SLG" = (round(sum(Single, na.rm = TRUE) + sum(Double, na.rm = TRUE) * 2 +
|
| 714 |
+
sum(Triple, na.rm = TRUE) * 3 + sum(HR, na.rm = TRUE))) / sum(AB, na.rm = TRUE)
|
| 715 |
+
) %>%
|
| 716 |
+
ungroup() %>%
|
| 717 |
+
arrange(desc(PitcherThrows),desc(Pitches)) %>%
|
| 718 |
+
gt() %>%
|
| 719 |
+
gt_theme_tim() %>%
|
| 720 |
+
fmt_number(columns = `Avg EV`:`Max EV`, decimals = 1) %>%
|
| 721 |
+
cols_label(AutoPitchType = "Type", PitcherThrows = "Hand") %>%
|
| 722 |
+
cols_width(
|
| 723 |
+
AutoPitchType ~ px(100),
|
| 724 |
+
Pitches ~ px(70),
|
| 725 |
+
PitcherThrows ~ px(70),
|
| 726 |
+
everything() ~ px(85)
|
| 727 |
+
) %>%
|
| 728 |
+
cols_align(align = "center") %>%
|
| 729 |
+
fmt_number(columns = AVG:SLG, decimals = 3) %>%
|
| 730 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 731 |
+
sub_missing() %>%
|
| 732 |
+
opt_interactive(
|
| 733 |
+
use_compact_mode = TRUE,
|
| 734 |
+
use_pagination = FALSE
|
| 735 |
+
)
|
| 736 |
+
})
|
| 737 |
+
output$InningFilterB <- render_gt({
|
| 738 |
+
test <- test %>% filter(BatterAndTeam == input$player) %>% group_by(Inning) %>%
|
| 739 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 740 |
+
summarise(
|
| 741 |
+
Pitches = n(),
|
| 742 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 743 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 744 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 745 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 746 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 747 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 748 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 749 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 750 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 751 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 752 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 753 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 754 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 755 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 756 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 757 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 758 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 759 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 760 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 761 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 762 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 763 |
+
ungroup()%>%
|
| 764 |
+
gt() %>%
|
| 765 |
+
gt_theme_tim() %>%
|
| 766 |
+
fmt_number(columns = `Avg EV`:`Max EV`,decimals = 1) %>%
|
| 767 |
+
cols_width(Inning:Pitches ~ px(70),
|
| 768 |
+
everything() ~ px(85)) %>%
|
| 769 |
+
cols_align(align = "center") %>%
|
| 770 |
+
fmt_number(columns = AVG:SLG,decimals = 3) %>%
|
| 771 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 772 |
+
sub_missing() %>%
|
| 773 |
+
#gt_theme_savant() %>%
|
| 774 |
+
opt_interactive(
|
| 775 |
+
use_compact_mode = TRUE,
|
| 776 |
+
use_pagination = FALSE
|
| 777 |
+
)
|
| 778 |
+
})
|
| 779 |
+
output$SideFilterB <- render_gt({
|
| 780 |
+
test1 <- test %>% filter(BatterAndTeam == input$player) %>% group_by(PitcherThrows) %>%
|
| 781 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 782 |
+
summarise(
|
| 783 |
+
Pitches = n(),
|
| 784 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 785 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 786 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 787 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 788 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 789 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 790 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 791 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 792 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 793 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 794 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 795 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 796 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 797 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 798 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 799 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 800 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 801 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 802 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 803 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 804 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 805 |
+
ungroup()
|
| 806 |
+
test2 <- test %>% mutate(PitcherThrows = "Both") %>% filter(BatterAndTeam == input$player) %>% group_by(PitcherThrows) %>%
|
| 807 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 808 |
+
summarise(
|
| 809 |
+
Pitches = n(),
|
| 810 |
+
#BBE = sum(BBE,na.rm = TRUE),
|
| 811 |
+
"Whiff%" = mean(Whiff[Swing == TRUE],na.rm = TRUE),
|
| 812 |
+
"SwStr%" = mean(Whiff,na.rm = TRUE),
|
| 813 |
+
"CSW%" = mean(CSW,na.rm = TRUE),
|
| 814 |
+
"Zone%" = mean(Zone,na.rm = TRUE),
|
| 815 |
+
"ZCon%" = mean(Contact[Zone == TRUE & Swing == TRUE],na.rm = TRUE),
|
| 816 |
+
"ZSwing%" = mean(Swing[Zone == TRUE],na.rm = TRUE),
|
| 817 |
+
"OCon%" = mean(Contact[Zone == FALSE & Swing == TRUE],na.rm = TRUE),
|
| 818 |
+
"OSwing%" = mean(Swing[Zone == FALSE],na.rm = TRUE),
|
| 819 |
+
"Avg EV" = mean(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 820 |
+
"EV90" = quantile(ExitSpeed[BBE == TRUE],.9,na.rm = TRUE),
|
| 821 |
+
"Max EV" = max(ExitSpeed[BBE == TRUE],na.rm = TRUE),
|
| 822 |
+
"Max EV" = ifelse(is.infinite(`Max EV`),NA,`Max EV`),
|
| 823 |
+
"GB%" = mean(GB[BBE == TRUE],na.rm = TRUE),
|
| 824 |
+
"LD%" = mean(LD[BBE == TRUE],na.rm = TRUE),
|
| 825 |
+
"FB%" = mean(FB[BBE == TRUE],na.rm = TRUE),
|
| 826 |
+
"AVG" = round(sum(Hit,na.rm = TRUE) / sum(AB,na.rm = TRUE),digits = 3),
|
| 827 |
+
"OBP" = round((sum(Hit,na.rm = TRUE) + sum(Walk,na.rm = TRUE) + sum(HBP,na.rm = TRUE))/
|
| 828 |
+
sum(PA,na.rm = TRUE),digits = 3),
|
| 829 |
+
"SLG" = (round(sum(Single,na.rm = TRUE) + sum(Double,na.rm = TRUE) * 2 +
|
| 830 |
+
sum(Triple,na.rm = TRUE) * 3 + sum(HR,na.rm = TRUE)))/sum(AB,na.rm = TRUE))%>%
|
| 831 |
+
ungroup()
|
| 832 |
+
test <- rbind(test1,test2)
|
| 833 |
+
test %>%
|
| 834 |
+
gt() %>%
|
| 835 |
+
gt_theme_tim() %>%
|
| 836 |
+
fmt_number(columns = `Avg EV`:`Max EV`,decimals = 1) %>%
|
| 837 |
+
cols_width(PitcherThrows:Pitches ~ px(70),
|
| 838 |
+
everything() ~ px(85)) %>%
|
| 839 |
+
cols_align(align = "center") %>%
|
| 840 |
+
cols_label(PitcherThrows = "Hand") %>%
|
| 841 |
+
fmt_number(columns = AVG:SLG,decimals = 3) %>%
|
| 842 |
+
fmt_percent(columns = ends_with("%")) %>%
|
| 843 |
+
sub_missing() %>%
|
| 844 |
+
#gt_theme_savant() %>%
|
| 845 |
+
opt_interactive(
|
| 846 |
+
use_compact_mode = TRUE,
|
| 847 |
+
use_pagination = FALSE
|
| 848 |
+
)
|
| 849 |
+
|
| 850 |
+
})
|
| 851 |
+
output$slashlineB <- render_gt({
|
| 852 |
+
test <- test %>% filter(BatterAndTeam == input$player) %>%
|
| 853 |
+
filter(between(as.Date(Date),input$date[1],input$date[2])) %>%
|
| 854 |
+
summarise(
|
| 855 |
+
Pitches = n(),
|
| 856 |
+
`1B` = sum(Single,na.rm = TRUE),
|
| 857 |
+
`2B` = sum(Double,na.rm = TRUE),
|
| 858 |
+
`3B` = sum(Triple,na.rm = TRUE),
|
| 859 |
+
HR = sum(HR,na.rm = TRUE),
|
| 860 |
+
SO = sum(Strikeout,na.rm = TRUE),
|
| 861 |
+
BB = sum(Walk,na.rm = TRUE),
|
| 862 |
+
Whiffs = sum(Whiff,na.rm = TRUE),
|
| 863 |
+
`Hard Hits` = sum(HardHit,na.rm = TRUE)
|
| 864 |
+
)%>%
|
| 865 |
+
ungroup()%>%
|
| 866 |
+
gt() %>%
|
| 867 |
+
gt_theme_tim() %>%
|
| 868 |
+
cols_align(align = "center") %>%
|
| 869 |
+
# gt_theme_savant() %>%
|
| 870 |
+
opt_interactive(
|
| 871 |
+
use_compact_mode = TRUE,
|
| 872 |
+
use_pagination = FALSE
|
| 873 |
+
)
|
| 874 |
+
})
|
| 875 |
+
|
| 876 |
}
|
| 877 |
|
| 878 |
# Run the application
|