forked from daattali/shiny-workshop-odsc2019
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp_07_sol.R
71 lines (60 loc) · 1.4 KB
/
app_07_sol.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
library(shiny)
library(ggplot2)
library(dplyr)
library(DT)
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
)
),
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({
ggplot(filtered_data(), aes(Salary)) +
geom_histogram() +
theme_classic() +
scale_x_log10(labels = scales::comma)
})
}
shinyApp(ui, server)