-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
app_09.R
83 lines (71 loc) · 1.81 KB
/
app_09.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
library(shiny)
library(ggplot2)
library(dplyr)
library(DT)
library(colourpicker)
players <- read.csv("data/nba2018.csv")
ui <- fluidPage(
titlePanel("NBA 2018/19 Player Stats"),
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),
selected = "Golden State Warriors",
multiple = TRUE
),
h3("Plot options"),
selectInput("variable", "Variable",
c("VORP", "Salary", "Age", "Height", "Weight"),
"Salary"),
radioButtons("plot_type", "Plot type", c("histogram", "density"))
),
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({
filtered_data()
})
output$num_players <- renderText({
nrow(filtered_data())
})
output$nba_plot <- renderPlot({
p <- ggplot(filtered_data(), aes_string(input$variable)) +
theme_classic() +
scale_x_log10(labels = scales::comma)
if (input$plot_type == "histogram") {
p <- p + geom_histogram()
} else if (input$plot_type == "density") {
p <- p + geom_density()
}
p
})
}
shinyApp(ui, server)