-
Notifications
You must be signed in to change notification settings - Fork 0
/
shiny_sh.Rmd
190 lines (160 loc) · 4.89 KB
/
shiny_sh.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
title: "Shiny Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(viridis)
## Loading required package: viridisLite
library(p8105.datasets)
library(plotly)
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()
```
```{r}
data("nyc_airbnb")
nyc_airbnb =
nyc_airbnb %>%
mutate(rating = review_scores_location / 2) %>%
rename(latitude = lat, longitude = long) %>%
select(
boro = neighbourhood_group, neighbourhood, rating, price, room_type,
latitude, longitude) %>%
filter(!is.na(rating))
```
Column {.sidebar}
-----------------------------------------------------------------------
```{r}
# boros = nyc_airbnb %>% distinct(boro) %>% pull()
#
# # selectInput widget
# selectInput(
# "boro_choice",
# label = h3("Select boro"),
# choices = boros, selected = "Manhattan")
#
# max_price = 1000
# min_price = nyc_airbnb %>% distinct(price) %>% min()
#
# # sliderInput widget
# sliderInput(
# "price_range",
# label = h3("Choose price range"),
# min = min_price, max = max_price, value = c(100, 400))
#
# room_choice = nyc_airbnb %>% distinct(room_type) %>% pull()
#
# # radioButtons widget
# radioButtons(
# "room_choice",
# label = h3("Choose room type"),
# choices = room_choice, selected = "Entire home/apt")
# country = world_cup %>% distinct(country,rank) %>% mutate(country = str_c(country, ", FIFA Rank", rank)) %>% select(country)
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))
```
```{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")
fit3
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{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) })
# renderPlotly({
# nyc_airbnb %>%
# filter(
# boro == input$boro_choice,
# price %in% input$price_range[1]:input$price_range[2],
# room_type == input$room_choice) %>%
# mutate(text_label = str_c("Price: $", price, '\nRating: ', rating)) %>%
# plot_ly(
# x = ~longitude, y = ~latitude, type = "scatter", mode = "markers",
# alpha = 0.5, color = ~price, text = ~text_label)
# })
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
renderPrint({
input[["price_range"]]
})
```
### Chart C
```{r}
renderPrint({
input[["boro_choice"]]
})
```