Update app.R
Browse files
app.R
CHANGED
|
@@ -9,42 +9,46 @@ library(httr)
|
|
| 9 |
library(patchwork) # For combining plots
|
| 10 |
|
| 11 |
check_patreon_access <- function(email) {
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
)
|
| 30 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
# Check conditions
|
| 41 |
-
if (tolower(user_email) == tolower(email) &&
|
| 42 |
-
patron_status == "active_patron" &&
|
| 43 |
-
(tier == "Veteran" || tier == "Hall of Fame")) {
|
| 44 |
-
return(TRUE)
|
| 45 |
-
}
|
| 46 |
}
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
download_private_csv <- function(repo_id, filename) {
|
| 50 |
url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename)
|
|
@@ -113,34 +117,34 @@ fsl <- download_private_csv("TimStats/StatcastDataAll", "FSL.csv")
|
|
| 113 |
|
| 114 |
ui <- page_fluid(
|
| 115 |
theme = bs_theme(bg = "#333333", fg = "#ffffff", primary = "#428bca"),
|
| 116 |
-
uiOutput("page_content")
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
)
|
| 145 |
|
| 146 |
# [Server code remains exactly the same]
|
|
|
|
| 9 |
library(patchwork) # For combining plots
|
| 10 |
|
| 11 |
check_patreon_access <- function(email) {
|
| 12 |
+
campaign_id <- Sys.getenv("PATREON_CAMPAIGN_ID")
|
| 13 |
+
access_token <- Sys.getenv("PATREON_ACCESS_TOKEN")
|
| 14 |
+
|
| 15 |
+
base_url <- paste0("https://www.patreon.com/api/oauth2/v2/campaigns/", campaign_id, "/members")
|
| 16 |
+
|
| 17 |
+
params <- list(
|
| 18 |
+
`include` = "currently_entitled_tiers",
|
| 19 |
+
`fields[member]` = "patron_status,email",
|
| 20 |
+
`fields[tier]` = "title"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
response <- GET(
|
| 24 |
+
base_url,
|
| 25 |
+
query = params,
|
| 26 |
+
add_headers(
|
| 27 |
+
`Authorization` = paste("Bearer", access_token),
|
| 28 |
+
`User-Agent` = "R/httr"
|
|
|
|
| 29 |
)
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
content <- fromJSON(rawToChar(response$content))
|
| 33 |
+
|
| 34 |
+
# Check in data$attributes for matching email
|
| 35 |
+
matching_row <- which(content$data$attributes$email == email)
|
| 36 |
+
|
| 37 |
+
if (length(matching_row) > 0) {
|
| 38 |
+
# Get patron status
|
| 39 |
+
patron_status <- content$data$attributes$patron_status[matching_row]
|
| 40 |
|
| 41 |
+
if (patron_status == "active_patron") {
|
| 42 |
+
# Get tier info
|
| 43 |
+
tier_data <- content$data$relationships$currently_entitled_tiers$data[[matching_row]]
|
| 44 |
+
|
| 45 |
+
result <- tier_id %in% c("25062087", "25062090")
|
| 46 |
+
|
| 47 |
+
return(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
return(FALSE)
|
| 52 |
}
|
| 53 |
download_private_csv <- function(repo_id, filename) {
|
| 54 |
url <- paste0("https://huggingface.co/datasets/", repo_id, "/resolve/main/", filename)
|
|
|
|
| 117 |
|
| 118 |
ui <- page_fluid(
|
| 119 |
theme = bs_theme(bg = "#333333", fg = "#ffffff", primary = "#428bca"),
|
| 120 |
+
uiOutput("page_content")
|
| 121 |
+
# card(
|
| 122 |
+
# card_header("2020-2024 Filterable Pitcher Heatmaps"),
|
| 123 |
+
# card(
|
| 124 |
+
# layout_columns(
|
| 125 |
+
# col_widths = c(4, 4, 4),
|
| 126 |
+
# card(
|
| 127 |
+
# selectInput("league", "Select League:", choices = c("MLB","AAA","FSL")),
|
| 128 |
+
# selectInput("player", "Select Player:", choices = c("")),
|
| 129 |
+
# sliderInput("concen", "Heatmap Bandwidth Factor", value = .75, step = 0.05, min = .5, max = 1.5)
|
| 130 |
+
# ),
|
| 131 |
+
# card(
|
| 132 |
+
# selectInput("hand1", "Batter Handedness", choices = c("All Batters","LHH","RHH")),
|
| 133 |
+
# selectInput("pitch1", "Pitch:", choices = c("")),
|
| 134 |
+
# dateRangeInput("date1", "Date Range:", start = "2024-02-09", end = "2024-09-05")
|
| 135 |
+
# ),
|
| 136 |
+
# card(
|
| 137 |
+
# selectInput("hand2", "Batter Handedness", choices = c("All Batters","LHH","RHH")),
|
| 138 |
+
# selectInput("pitch2", "Pitch:", choices = c("")),
|
| 139 |
+
# dateRangeInput("date2", "Date Range:", start = "2024-02-09", end = "2024-09-05")
|
| 140 |
+
# )
|
| 141 |
+
# )
|
| 142 |
+
# ),
|
| 143 |
+
# card(
|
| 144 |
+
# downloadButton("download", "Download Plot", class = "btn-primary mb-3"),
|
| 145 |
+
# plotOutput("combined_graph", height = "600px")
|
| 146 |
+
# )
|
| 147 |
+
# )
|
| 148 |
)
|
| 149 |
|
| 150 |
# [Server code remains exactly the same]
|