-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.R
executable file
·175 lines (151 loc) · 4.69 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
renv::load()
suppressPackageStartupMessages({
library(shiny)
library(shinyWidgets)
library(shinyjs)
library(bs4Dash)
library(dplyr)
library(ffscrapr)
library(DT)
library(waiter)
library(writexl)
options(dplyr.summarise.inform = FALSE)
})
ui <- dashboardPage(
dark = NULL,
header = dashboardHeader(
h4("ESPN Potential Points Calculator", style = "color:#fff;"),
title = dashboardBrand(
"DynastyProcess.com",
color = "gray-dark",
image = "https://raw.githubusercontent.com/dynastyprocess/graphics/main/.dynastyprocess/logohexonly.png"),
status = "gray-dark",
fixed = TRUE,
border = TRUE,
skin = "dark"
),
sidebar = dashboardSidebar(
skin = "dark",
sidebarMenu(
menuItem("Potential Points", icon = icon("calculator")),
tags$li(
tags$a(
icon("quidditch",class = "nav-icon"),
p("More by DynastyProcess"),
class = "nav-link",
href = "https://dynastyprocess.com"
), class = "nav-item")
)
),
body = dashboardBody(
includeCSS("dp.css"),
waiter::useWaiter(),
waiter::waiterOnBusy(html = waiter::spin_dots(), color = waiter::transparent(0.5)),
shinyjs::useShinyjs(),
fluidRow(
box(
title = "Inputs",
width = 3,
status = "gray-dark",
solidHeader = TRUE,
fluidRow(
column(
width = 12,
pickerInput("season",
label = "Season",
choices = nflreadr:::most_recent_season():2018,
selected = nflreadr:::most_recent_season()),
textInput("league_id",
label = "League ID",
value = "1178049"),
tags$details(
tags$summary("Add Authentication Cookies"),
textInput("swid",
label = "SWID"),
textInput("espn_s2",
label = "ESPN S2"),
markdown("You can find the values for cookies by following these [instructions](https://ffscrapr.ffverse.com/articles/espn_authentication.html).")
)
)
),
footer = div(
actionButton("load", label = "Calculate!"),
shinyjs::hidden(downloadButton("download", label = "Download")),
style = "text-align:center;")
),
column(width = 9, uiOutput("potential_points"))
)
)
)
server <- function(input, output, session) {
potential_points <- reactiveVal()
observeEvent(input$load,{
req(input$season)
req(input$league_id)
conn <- espn_connect(input$season,input$league_id, swid = input$swid, espn_s2 = input$espn_s2)
player_week <- espn_potentialpoints(conn)
week <- player_week %>%
group_by(week, franchise_id, franchise_name, franchise_score) %>%
summarise(
optimal_score = sum(player_score * !is.na(optimal_slot), na.rm = TRUE),
) %>%
ungroup() %>%
mutate(efficiency = round(franchise_score/optimal_score,3))
season <- week %>%
group_by(franchise_id, franchise_name) %>%
summarise(
franchise_score = sum(franchise_score, na.rm = TRUE),
optimal_score = sum(optimal_score, na.rm = TRUE)
) %>%
ungroup() %>%
mutate(efficiency = round(franchise_score/optimal_score,3))
list(
week_details = player_week,
week_summary = week,
season_summary = season
) %>%
potential_points()
})
fn_tabPanel <- function(x,x_name){
tabPanel(title = x_name,
DT::datatable(x,
rownames = FALSE,
class = "compact stripe nowrap",
filter = "top",
width = "100%",
options = list(scrollX = TRUE)
)
# tantastic::fmt_dtcol(x,c("franchise_score","optimal_score","efficiency"))
)
}
output$potential_points <- renderUI({
req(potential_points())
shinyjs::show("download")
player_week <- fn_tabPanel(potential_points()$week_details,"Week Details")
week <- fn_tabPanel(potential_points()$week_summary,"Week Summary")
season <- fn_tabPanel(potential_points()$season_summary,"Season Summary")
tabBox(
title = "Potential Points",
side = "right",
width = 12,
status = "gray-dark",
solidHeader = TRUE,
type = "pills",
season,
week,
player_week
)
# tagList(
# season,
# week,
# player_week
# )
})
output$download <- downloadHandler(
filename = "ESPN_PP.xlsx",
content = function(file){
writexl::write_xlsx(potential_points(),path = file,format_headers = TRUE)
}
)
}
shinyApp(ui, server)