Movie1

Row 1

The world of movies

Welcome to the World of Movies dashboard incorporating movie data from Movielens. We have 62423 movies to choose from…

Movies List

Shiny applications not supported in static R Markdown documents

Row 2

Table1

View your movie

This is the link: View my movie : )

Data Checks

# A tibble: 1 × 4
  movieId title        genres                                      year 
    <dbl> <chr>        <chr>                                       <chr>
1       1 "Toy Story " Adventure Animation Children Comedy Fantasy 1995 
# A tibble: 1 × 4
  movieId title                      genres                 year 
    <dbl> <chr>                      <chr>                  <chr>
1  209171 "Women of Devil's Island " Action Adventure Drama 1962 
# A tibble: 1 × 3
  movieId imdbId  tmdbId
    <dbl> <chr>    <dbl>
1       1 0114709    862
# A tibble: 1 × 3
  movieId imdbId  tmdbId
    <dbl> <chr>    <dbl>
1  209171 0055323  79513
NULL
# A tibble: 6 × 4
  movieId title                          genres                            year 
    <dbl> <chr>                          <chr>                             <chr>
1       1 "Toy Story "                   Adventure Animation Children Com… 1995 
2       2 "Jumanji "                     Adventure Children Fantasy        1995 
3       3 "Grumpier Old Men "            Comedy Romance                    1995 
4       4 "Waiting to Exhale "           Comedy Drama Romance              1995 
5       5 "Father of the Bride Part II " Comedy                            1995 
6       6 "Heat "                        Action Crime Thriller             1995 
cols(
  movieId = col_double(),
  imdbId = col_character(),
  tmdbId = col_double()
)
# A tibble: 6 × 3
  movieId imdbId  tmdbId
    <dbl> <chr>    <dbl>
1       1 0114709    862
2       2 0113497   8844
3       3 0113228  15602
4       4 0114885  31357
5       5 0113041  11862
6       6 0113277    949

References

Data Reference F. Maxwell Harper and Joseph A. Konstan. 2015. The MovieLens Datasets: History and Context. ACM Transactions on Interactive Intelligent Systems (TiiS) 5, 4: 19:1–19:19. https://doi.org/10.1145/2827872

https://cran.r-project.org/web/packages/i2dash/vignettes/i2dash-intro.html

https://epirhandbook.com/en/dashboards-with-r-markdown.html

https://testing-apps.shinyapps.io/flexdashboard-leaflet-waste/

https://www.jumpingrivers.com/blog/r-clickable-wordcloud-javascript-shiny/

---
title: "Assignment 3"
author: "Ben Taylor - s4025165"
subtitle: Storytelling with open data
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
# Do not change these settings!
knitr::opts_chunk$set(warning = FALSE, message = FALSE)

```

```{r}
# Load the required libraries
#install.packages("i2dash", dependencies = TRUE) #Used for creation of the dashboard
library(i2dash)
#install.packages(c("leaflet"))
library(leaflet)
library(plotly)
library(RColorBrewer)
library(dplyr)
library(magrittr)
library(ggplot2)
library(readxl)
library(data.table)
library(tidyverse)
library(tidytext)
library(scales)
library(stringr)
library(htmltools)
library(wordcloud2)

```


```{r}

# Load the Movie
MovieData <- read_csv("movies.csv")
MovieLinkData <- read_csv("links.csv")

# Perform some tidy up
# Add a 'Year' column and split this out from the Title field
#str_trim(MovieData$title)
MovieData %<>% 
  mutate(year = substr(MovieData$title, (nchar(MovieData$title)-4), (nchar(MovieData$title)-1)))

# Remove the Date from the Movie Title
MovieData$title <- substring(MovieData$title, 1, nchar(MovieData$title)-6)

# Convert the pipe symbol to a space
MovieData$genres <- str_replace_all(MovieData$genres,"\\|"," ")
# Need to make sci-fi one word so that it appears neatly in the Wordcloud
MovieData$genres <- str_replace(MovieData$genres, "Sci-Fi", "SciFi")
# Need to make (no generes listes) as 'OpenGenre' so that it appears neatly in the Wordcloud
MovieData$genres <- str_replace(MovieData$genres, "(no genres listed)", "OpenGenre")
# Need to make Film-Noir one word so that it appears neatly in the Wordcloud
MovieData$genres <- str_replace(MovieData$genres, "Film-Noir", "FilmNoir")
```

# Movie1
## Row 1 {data-height=650}
### The world of movies
Welcome to the World of Movies dashboard incorporating movie data from <b><u><a href='https://movielens.org/'>Movielens</a></u></b>. We have `r nrow(MovieData)` movies to choose from...
```{r}
# Create a Word Cloud of all of the Genres
word_counts = MovieData %>%
  unnest_tokens("genres", genres) %>%
  #anti_join(stop_words, by = "genres") %>%
  count(genres) %>%
  filter(n > 10)

#word_counts %>%
#  arrange(desc(n))

# Chose a colour friendly palette
wordcloud_palette = c("#355070",
                      "#6d597a",
                      "#b56576",
                      "#e56b6f",
                      "#eaac8b")

movie_wordcloud = wordcloud2(
  word_counts,
  color = rep_len(wordcloud_palette,
                  nrow(word_counts)))
movie_wordcloud

```

### Movies List
```{r}
library("shiny")
ui = fluidPage(
  wordcloud2Output("wordcloud")
)

server = function(input, output) {
  output$wordcloud = renderWordcloud2(movie_wordcloud)
}

shinyApp(ui, server)

ui = fluidPage(
  tags$script(HTML(
    "$(document).on('click', '#canvas', function() {
      word = $('#wcLabel').text();
      Shiny.onInputChange('clicked_word', word);
    });")),
  wordcloud2Output("wordcloud")
)

server = function(input, output) {
  output$wordcloud = renderWordcloud2(my_wordcloud)
  
  filtered_movies = reactive({
    clicked_word = str_remove(input$clicked_word, ":[0-9]+$")
    
    MovieData %>%
      filter(str_detect(tolower(genres), clicked_word)) %>%
      select(genres, everything(), -show_id)
  })
}



```


## Row 2 {data-height=350}
### Table1
### View your movie
```{r}
browsable(
  tags$p(
    "This is the link: ", 
    tags$a(
      href = "https://www.imdb.com/title/tt0076759/",
      "View my movie : )"
    )
  )
)
#webshot("https://www.imdb.com/title/tt0076759/")
```

# Data Checks
```{r}
# Check the data load
# Check the first and last rows of the dataset to make sure we loaded everything
firstrow <- head(MovieData, n = 1)
head(firstrow)
lastrow <- tail(MovieData, n = 1)
head(lastrow)

firstrow <- head(MovieLinkData, n = 1)
head(firstrow)
lastrow <- tail(MovieLinkData, n = 1)
head(lastrow)

# Confirm all the data is correct - there should be zero 'Unknowns'
#table(MovieData$year, useNA = "always")

# Show the Data Types for each column
spec(MovieData)
#Show a short tibble of the data to see what it looks like
head(MovieData)

# Show the Data Types for each column
spec(MovieLinkData)
#Show a short tibble of the data to see what it looks like
head(MovieLinkData)

```


# References

**Data Reference**
F. Maxwell Harper and Joseph A. Konstan. 2015. The MovieLens Datasets: History and Context. ACM Transactions on Interactive Intelligent Systems (TiiS) 5, 4: 19:1–19:19. <https://doi.org/10.1145/2827872>

https://cran.r-project.org/web/packages/i2dash/vignettes/i2dash-intro.html

https://epirhandbook.com/en/dashboards-with-r-markdown.html

https://testing-apps.shinyapps.io/flexdashboard-leaflet-waste/

https://www.jumpingrivers.com/blog/r-clickable-wordcloud-javascript-shiny/