-
Notifications
You must be signed in to change notification settings - Fork 0
/
shiny_dashboard_template.Rmd
128 lines (105 loc) · 3.46 KB
/
shiny_dashboard_template.Rmd
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
---
title: "Shiny Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(dplyr)
library(readr)
library(shiny)
library(shinyWidgets)
library(plotly)
library(viridis)
library(rsconnect)
```
```{r import_data, include=FALSE}
world_cup = read_csv("./data/worldcup_final.csv") %>%
janitor::clean_names() %>%
select(country,w, pld, d, rank, gf, ga)
##filter(country %in% c("Ecuador", "Argentina", "Brazil", "England", "France", "Spain", "Belgium", "Portugal", "Germany", "Netherlands", "Uruguay", "Croatia", "Denmark", "Mexico", "United States", "Senegal", "Wales", "Poland", "Australia", "Japan", "Morocco", "Switzerland", "Ghana", "South Korea","Cameroon", "Serbia", "Canada", "Costa Rica", "Tunisia", "Saudi Arabia", "Iran", "Ecuador"))
## Even though there are currently 32 countries who made it to World Cup 2022, since this is Qatar's first time at the World Cup it is not in our original data set therefore we only have 31 countries.
##
min_w = world_cup %>% distinct(w) %>% min()
min_pld = world_cup %>% distinct(pld) %>% min()
min_d = world_cup %>% distinct(d) %>% min()
min_gf = world_cup %>% distinct(gf) %>% min()
min_ga = world_cup %>% distinct(ga) %>% min()
max_w = world_cup %>% distinct(w) %>% max()
max_pld = world_cup %>% distinct(pld) %>% max()
max_d = world_cup %>% distinct(d) %>% max()
max_gf = world_cup %>% distinct(gf) %>% max()
max_ga = world_cup %>% distinct(ga) %>% max()
```
Column {.sidebar}
-----------------------------------------------------------------------
This flexdashboard with shiny shows our linear model prediction tool for number of wins
in the Wold Cup.
### Sliders for our linear model
```{r}
country = world_cup %>% distinct(country) %>% pull()
# selectInput widget
selectInput(
"country_choice",
label = h3("Select country"),
choices = country)
# sliderInput widget for pld
sliderInput(
"number_games_range",
label = h3("Choose number games range"),
min = 0, max = max_pld, value = c(113))
# sliderInput widget for d
sliderInput(
"draw_games_range",
label = h3("Choose draw games range"),
min = min_d, max = max_d, value = c(22))
# sliderInput widget for gf
sliderInput(
"goals_for_range",
label = h3("Choose goals for range"),
min = min_gf, max = max_gf, value = c(236))
# sliderInput widget for ga
sliderInput(
"goals_against_range",
label = h3("Choose goals against range"),
min = min_ga, max = max_ga, value = c(130))
```
Column {data-width=650}
-----------------------------------------------------------------------
### FIFA 2022 Games Won Predictor Tool
```{r}
fit3 =
world_cup %>%
lm(w ~ pld + d + rank + gf + ga, data = .) %>%
broom::tidy() %>%
as_tibble() %>%
select(term, estimate) %>%
pivot_wider(
names_from = "term",
values_from = "estimate")
```
```{r}
renderTable({
world_cup %>%
filter(
country == input$country_choice) %>%
mutate(pld = input$number_games_range[1],
d = input$draw_games_range[1],
gf = input$goals_for_range[1],
ga = input$goals_against_range[1],
results = -1.56 + 0.660*pld - 0.628*d + 0.0159*rank + 0.154*gf - 0.224*ga) })
```
input$country_choice
h3("Here is that value:")
Column {data-width=650}
--------------------------------------------------------------------------
```{r}
renderPrint({
input[["country_choice"]]
})
```