Update app.R
Browse files
app.R
CHANGED
|
@@ -27,27 +27,51 @@ options(shiny.maxRequestSize = 10000000 * 1024^2)
|
|
| 27 |
pdf(file = NULL)
|
| 28 |
Sys.setenv(TZ='EST')
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
-
# Usage
|
| 48 |
-
t <- download_private_csv("TimStats/Passwords", "demo.csv")
|
| 49 |
-
pass <- t[1,1]
|
| 50 |
-
|
| 51 |
model <- xgb.load('TimStuff2.model')
|
| 52 |
|
| 53 |
# Helper functions
|
|
@@ -547,31 +571,50 @@ summary_table <- function(game) {
|
|
| 547 |
|
| 548 |
# Modify the UI
|
| 549 |
ui <- fluidPage(
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
)
|
| 568 |
)
|
| 569 |
)
|
| 570 |
)
|
|
|
|
|
|
|
| 571 |
|
| 572 |
-
# Server Definition
|
| 573 |
-
server <- function(input, output, session) {
|
| 574 |
-
|
| 575 |
game_data <- reactiveVal()
|
| 576 |
|
| 577 |
observeEvent(input$update, {
|
|
|
|
| 27 |
pdf(file = NULL)
|
| 28 |
Sys.setenv(TZ='EST')
|
| 29 |
|
| 30 |
+
check_patreon_access <- function(email) {
|
| 31 |
+
campaign_id <- Sys.getenv("PATREON_CAMPAIGN_ID")
|
| 32 |
+
access_token <- Sys.getenv("PATREON_ACCESS_TOKEN")
|
| 33 |
+
|
| 34 |
+
base_url <- paste0("https://www.patreon.com/api/oauth2/v2/campaigns/", campaign_id, "/members")
|
| 35 |
+
|
| 36 |
+
params <- list(
|
| 37 |
+
`include` = "currently_entitled_tiers",
|
| 38 |
+
`fields[member]` = "patron_status,email",
|
| 39 |
+
`fields[tier]` = "title"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
response <- GET(
|
| 43 |
+
base_url,
|
| 44 |
+
query = params,
|
| 45 |
+
add_headers(
|
| 46 |
+
`Authorization` = paste("Bearer", access_token),
|
| 47 |
+
`User-Agent` = "R/httr"
|
| 48 |
+
)
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
content <- fromJSON(rawToChar(response$content))
|
| 52 |
+
|
| 53 |
+
# Check in data$attributes for matching email
|
| 54 |
+
matching_row <- which(content$data$attributes$email == email)
|
| 55 |
+
|
| 56 |
+
if (length(matching_row) > 0) {
|
| 57 |
+
# Get patron status
|
| 58 |
+
patron_status <- content$data$attributes$patron_status[matching_row]
|
| 59 |
+
|
| 60 |
+
if (patron_status == "active_patron") {
|
| 61 |
+
# Get tier info
|
| 62 |
+
tier_data <- content$data$relationships$currently_entitled_tiers$data[[matching_row]]
|
| 63 |
+
|
| 64 |
+
tier_id <- tier_data$id
|
| 65 |
+
|
| 66 |
+
result <- tier_id %in% c("25062087", "25062090")
|
| 67 |
+
|
| 68 |
+
return(result)
|
| 69 |
+
}
|
| 70 |
}
|
| 71 |
+
|
| 72 |
+
return(FALSE)
|
| 73 |
}
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
model <- xgb.load('TimStuff2.model')
|
| 76 |
|
| 77 |
# Helper functions
|
|
|
|
| 571 |
|
| 572 |
# Modify the UI
|
| 573 |
ui <- fluidPage(
|
| 574 |
+
uiOutput("page")
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
+
# Server Definition
|
| 578 |
+
server <- function(input, output, session) {
|
| 579 |
+
|
| 580 |
+
output$page <- renderUI({
|
| 581 |
+
if (!credentials$logged_in) {
|
| 582 |
+
# Login page
|
| 583 |
+
div(class = "login-screen",
|
| 584 |
+
div(class = "login-header",
|
| 585 |
+
h2("Baseball Stats Visualization"),
|
| 586 |
+
p("Please log in with your Patreon email")
|
| 587 |
+
),
|
| 588 |
+
textInput("email", "Email:"),
|
| 589 |
+
actionButton("login", "Login", class = "btn-primary"),
|
| 590 |
+
p(style = "margin-top: 20px; text-align: center;",
|
| 591 |
+
"Access requires Veteran or Hall of Fame tier on Patreon")
|
| 592 |
+
)
|
| 593 |
+
} else {
|
| 594 |
+
fluidPage(
|
| 595 |
+
titlePanel("Trackman Summary Card Demo"),
|
| 596 |
+
sidebarLayout(
|
| 597 |
+
sidebarPanel(
|
| 598 |
+
width = 3,
|
| 599 |
+
fileInput("incsv", "Input File", accept = c(".csv"), multiple = FALSE),
|
| 600 |
+
actionButton("update", "Load Pitchers", icon("magnifying-glass"),
|
| 601 |
+
class = "btn-primary btn-block"),
|
| 602 |
+
selectizeInput("pitcher", "Pitcher Name:", NULL),
|
| 603 |
+
numericInput("rollnum", "Rolling Pitch #", c("1")),
|
| 604 |
+
actionButton("update1", "Make Card", icon("plus"),
|
| 605 |
+
class = "btn-success btn-block"),
|
| 606 |
+
downloadButton("downloadPlot", "Download Card", class = "btn-info btn-block")
|
| 607 |
+
),
|
| 608 |
+
mainPanel(
|
| 609 |
+
div(style = "width: 1000px; height: 1000px; overflow: auto;",
|
| 610 |
+
plotOutput("combinedPlot", width = "100%", height = "100%")
|
| 611 |
)
|
| 612 |
)
|
| 613 |
)
|
| 614 |
)
|
| 615 |
+
}
|
| 616 |
+
})
|
| 617 |
|
|
|
|
|
|
|
|
|
|
| 618 |
game_data <- reactiveVal()
|
| 619 |
|
| 620 |
observeEvent(input$update, {
|