-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
75 lines (67 loc) · 2.28 KB
/
app.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
#loading the libraries
library(shiny)
library(tidyverse)
#reading the csv file and transforming some data
netflix <- read_csv("netflix_titles.csv")
netflixYear <- unique(netflix$release_year)
netflixRating <- sort(unique(netflix$rating))
ui <- fluidPage(
# Application title
titlePanel("Netflix Data"),
sidebarLayout(
sidebarPanel(
#year selection
sliderInput(inputId = "years",
label = "Select Release Year",
min = 1980,
max = max(netflixYear),
value = c(1990, 2010),
sep = ""
),
#rating selection
selectInput(
inputId = "rating",
label = "Select ratings",
choices = netflixRating,
selected = sample(netflixRating, 1),
multiple = TRUE
)
),
mainPanel(
plotOutput("releases"),
plotOutput("ratings")
)
)
)
# server logic
server <- function(input, output) {
output$releases <- renderPlot({
netflix %>%
filter(release_year > input$years[1] & release_year < input$years[2]) %>%
group_by(release_year) %>%
summarize(count = n()) %>%
arrange(desc(count)) %>%
ggplot(aes(reorder(release_year, count), count, fill = release_year)) +
geom_bar(stat = "identity", width = 0.9) +
xlab("Year") +
ylab("Number of movies") +
ggtitle("Number of releases") +
coord_flip()
})
output$ratings <- renderPlot ({
netflix %>%
#choosing only the non-empty values from the list selected by the user
filter(!is.na(rating) & rating %in% input$rating) %>%
group_by(rating) %>%
summarize(count = n()) %>%
arrange(desc(count)) %>%
ggplot(aes(reorder(rating, count), count, fill = rating)) +
geom_bar(stat = "identity", width = 0.8) +
coord_flip() +
xlab("TV ratings") +
ylab("No of movies") +
ggtitle("Ratings with the biggest number of releases")
})
}
# running the app
shinyApp(ui = ui, server = server)