Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -7,13 +7,23 @@ library(shinyjs)
|
|
| 7 |
|
| 8 |
# ββ Load data ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 9 |
load_data <- function(level) {
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
load_scores <- function(level) {
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
|
| 19 |
load_portal <- function() {
|
|
@@ -202,6 +212,8 @@ ui <- fluidPage(
|
|
| 202 |
|
| 203 |
.portal-yes { color:#00840D; font-weight:700; }
|
| 204 |
.portal-no { color:#aaa; font-weight:400; }
|
|
|
|
|
|
|
| 205 |
|
| 206 |
.modal-overlay { position:fixed; top:0; left:0; width:100%; height:100%;
|
| 207 |
background:rgba(0,0,0,0.55); z-index:2000;
|
|
@@ -296,12 +308,11 @@ ui <- fluidPage(
|
|
| 296 |
tags$img(src = "Butler-Bulldogs-Logo-1990.png", height = "52px")
|
| 297 |
),
|
| 298 |
|
| 299 |
-
# filters
|
| 300 |
tags$div(class = "filters",
|
| 301 |
tags$div(
|
| 302 |
tags$div("Level", class = "filter-label"),
|
| 303 |
selectInput("level", label = NULL,
|
| 304 |
-
choices = c("D1","D2","D3","JUCO","NAIA"),
|
| 305 |
selected = "D1", width = "160px")
|
| 306 |
),
|
| 307 |
tags$div(
|
|
@@ -314,9 +325,13 @@ ui <- fluidPage(
|
|
| 314 |
tags$div("Min Pitches", class = "filter-label"),
|
| 315 |
numericInput("min_pitches", label = NULL,
|
| 316 |
value = 100, min = 1, max = 2000, step = 25, width = "160px")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
)
|
| 318 |
),
|
| 319 |
-
|
| 320 |
# main
|
| 321 |
tags$div(class = "main",
|
| 322 |
uiOutput("main_ui")
|
|
@@ -355,20 +370,22 @@ server <- function(input, output, session) {
|
|
| 355 |
|
| 356 |
stats_table <- reactive({
|
| 357 |
req(raw_data(), input$min_pitches)
|
| 358 |
-
if (input$position == "Pitcher")
|
| 359 |
-
tryCatch(
|
| 360 |
-
build_pitcher_stats(
|
| 361 |
raw_data()$df,
|
| 362 |
input$min_pitches,
|
| 363 |
raw_data()$scores,
|
| 364 |
raw_data()$portal
|
| 365 |
-
)
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
|
|
|
| 372 |
})
|
| 373 |
|
| 374 |
output$main_ui <- renderUI({
|
|
|
|
| 7 |
|
| 8 |
# ββ Load data ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 9 |
load_data <- function(level) {
|
| 10 |
+
if (level == "All") {
|
| 11 |
+
dplyr::bind_rows(lapply(c("D1","D2","D3","JUCO","NAIA"), function(l) {
|
| 12 |
+
arrow::read_parquet(paste0("/app/", l, ".parquet"))
|
| 13 |
+
}))
|
| 14 |
+
} else {
|
| 15 |
+
arrow::read_parquet(paste0("/app/", gsub("[^A-Za-z0-9]","_",level), ".parquet"))
|
| 16 |
+
}
|
| 17 |
}
|
| 18 |
|
| 19 |
load_scores <- function(level) {
|
| 20 |
+
if (level == "All") {
|
| 21 |
+
dplyr::bind_rows(lapply(c("D1","D2","D3","JUCO","NAIA"), function(l) {
|
| 22 |
+
arrow::read_parquet(paste0("/app/", l, "_scores.parquet"))
|
| 23 |
+
}))
|
| 24 |
+
} else {
|
| 25 |
+
arrow::read_parquet(paste0("/app/", level, "_scores.parquet"))
|
| 26 |
+
}
|
| 27 |
}
|
| 28 |
|
| 29 |
load_portal <- function() {
|
|
|
|
| 212 |
|
| 213 |
.portal-yes { color:#00840D; font-weight:700; }
|
| 214 |
.portal-no { color:#aaa; font-weight:400; }
|
| 215 |
+
.checkbox label { font-size:13px; color:#333; font-weight:500; }
|
| 216 |
+
.checkbox input[type='checkbox'] { margin-right:6px; }
|
| 217 |
|
| 218 |
.modal-overlay { position:fixed; top:0; left:0; width:100%; height:100%;
|
| 219 |
background:rgba(0,0,0,0.55); z-index:2000;
|
|
|
|
| 308 |
tags$img(src = "Butler-Bulldogs-Logo-1990.png", height = "52px")
|
| 309 |
),
|
| 310 |
|
|
|
|
| 311 |
tags$div(class = "filters",
|
| 312 |
tags$div(
|
| 313 |
tags$div("Level", class = "filter-label"),
|
| 314 |
selectInput("level", label = NULL,
|
| 315 |
+
choices = c("All","D1","D2","D3","JUCO","NAIA"),
|
| 316 |
selected = "D1", width = "160px")
|
| 317 |
),
|
| 318 |
tags$div(
|
|
|
|
| 325 |
tags$div("Min Pitches", class = "filter-label"),
|
| 326 |
numericInput("min_pitches", label = NULL,
|
| 327 |
value = 100, min = 1, max = 2000, step = 25, width = "160px")
|
| 328 |
+
),
|
| 329 |
+
tags$div(
|
| 330 |
+
tags$div("Portal Only", class = "filter-label"),
|
| 331 |
+
checkboxInput("portal_only", label = "Show Portal Players Only",
|
| 332 |
+
value = FALSE)
|
| 333 |
)
|
| 334 |
),
|
|
|
|
| 335 |
# main
|
| 336 |
tags$div(class = "main",
|
| 337 |
uiOutput("main_ui")
|
|
|
|
| 370 |
|
| 371 |
stats_table <- reactive({
|
| 372 |
req(raw_data(), input$min_pitches)
|
| 373 |
+
if (input$position == "Pitcher") {
|
| 374 |
+
tryCatch({
|
| 375 |
+
df <- build_pitcher_stats(
|
| 376 |
raw_data()$df,
|
| 377 |
input$min_pitches,
|
| 378 |
raw_data()$scores,
|
| 379 |
raw_data()$portal
|
| 380 |
+
)
|
| 381 |
+
if (input$portal_only) df <- df %>% filter(Portal == "Yes")
|
| 382 |
+
df
|
| 383 |
+
}, error = function(e) {
|
| 384 |
+
message("build_pitcher_stats failed: ", e$message)
|
| 385 |
+
showNotification(paste("Stats error:", e$message), type = "error")
|
| 386 |
+
NULL
|
| 387 |
+
})
|
| 388 |
+
}
|
| 389 |
})
|
| 390 |
|
| 391 |
output$main_ui <- renderUI({
|