-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
app_full_version.R
103 lines (89 loc) · 2.52 KB
/
app_full_version.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
library(shiny)
library(dplyr)
library(ggplot2)
library(colourpicker)
library(DT)
library(readr)
players <- read_csv("data/nba2018.csv", col_types = cols())
ui <- fluidPage(
titlePanel("NBA 2018/19 Player Stats"),
checkboxInput("full_version", strong("SHOW FULL VERSION"), value = TRUE),
sidebarLayout(
sidebarPanel(
"Exploring all player stats from the NBA 2018/19 season",
h3("Filters"),
sliderInput(
inputId = "VORP",
label = "Player VORP rating at least",
min = -3, max = 10,
value = c(0, 10)
),
selectInput(
"Team", "Team",
unique(players$Team),
multiple = TRUE
),
conditionalPanel(
"input.full_version",
h3("Plot options"),
selectInput("variable", "Variable",
c("VORP", "Salary", "Age", "Height", "Weight"),
"Salary"),
radioButtons("plot_type", "Plot type", c("histogram", "density")),
checkboxInput("log", "Log scale", value = TRUE),
numericInput("size", "Font size", 16),
colourInput("col", "Line colour", "blue")
)
),
mainPanel(
strong(
"There are",
textOutput("num_players", inline = TRUE),
"players in the dataset"
),
plotOutput("nba_plot"),
DTOutput("players_data")
)
)
)
server <- function(input, output, session) {
filtered_data <- reactive({
players <- players %>%
filter(VORP >= input$VORP[1],
VORP <= input$VORP[2])
if (length(input$Team) > 0) {
players <- players %>%
filter(Team %in% input$Team)
}
players
})
output$players_data <- renderDT({
datatable(filtered_data()) %>% formatCurrency('Salary')
})
output$num_players <- renderText({
nrow(filtered_data())
})
output$nba_plot <- renderPlot({
if (input$full_version) {
p <- ggplot(filtered_data(), aes_string(input$variable)) +
theme_classic(input$size)
if (input$plot_type == "histogram") {
p <- p + geom_histogram(fill = input$col, colour = "black")
} else if (input$plot_type == "density") {
p <- p + geom_density(fill = input$col)
}
if (input$log) {
p <- p + scale_x_log10(labels = scales::comma)
} else {
p <- p + scale_x_continuous(labels = scales::comma)
}
} else {
p <- ggplot(filtered_data(), aes(Salary)) +
geom_histogram() +
theme_classic() +
scale_x_log10(labels = scales::comma)
}
p
})
}
shinyApp(ui, server)