Written on

What Should I Watch?

Found in [R , tutorials , movies] by @awhstin on

Another entry in the series intended to help both you and me spend our time I put together this ‘app’ where it randomly selects a movie from the list of movies on Wikipedia that have won Academy Awards.


How To:

library(shiny)
library(shinyWidgets)
library(tidyverse)
library(rvest)
library(extrafont)

#Data saved locally but can be acquired from the Wikipedia site
wiki<-readRDS('wiki.rds')

#UI with Styling
ui <- fluidPage(
    tags$head(
        tags$style(HTML("
      @import url('//fonts.googleapis.com/css?family=Inconsolata|Merriweather');
                        
                         h1 {
        font-family: 'Merriweather', cursive;
        font-weight: 700;
        line-height: 1.1;
                         }
      h3 {
        font-family: 'Inconsolata', cursive;
        font-weight: 700;
        line-height: 1.1;
      }
      h5 {
        font-family: 'Inconsolata', cursive;
        font-weight: 400;
        line-height: 1.1;
      }
      h6 {
        font-family:'Merriweather';
        font-weight:400;
        font-color:#d3d3d3;
        text-align:right;
      }
      
      #go {
      background-color:#fff;
      font-family:'Inconsolata';
      font-weight:400;
      font-size:20px;
      border-color:#222222;}"))),
    
    fluidRow(column(width = 1),
    column(width=10,align='center',br(),actionButton("go", "What Should I Watch?")),
    column(width=1)),
    fluidRow(column(width = 1),
             column(width=10,fluidRow(align='center',br(), 
                                      h1(textOutput('film')),
                                      h3(textOutput('year')), 
                                      h5(textOutput('caption')),
                                      br(),
                                      h6('Data: Wikipedia'),
                                      h6(HTML('<a href="https://en.wikipedia.org/wiki/List_of_Academy_Award-winning_films">List of Academy Award-winning films</a>')))),
             column(width=1))
   
   
)


# Server Logic
server <- function(input, output, session) {
    observeEvent(input$go,{
        selected <- wiki %>%
            mutate(inputs=input$go) %>%
            filter(row.names(.) == sample(1:nrow(wiki),1)) %>%
            mutate(Film=Film)

    output$film <- renderText({
        selected$Film
    })
    output$year <- renderText({
        selected$Year
    })
    output$caption <- renderText({
        paste(selected$Film,'won',selected$Awards,'academy awards & was nominated',selected$Nominations,'times.')
    })
    })

}


# Run the application 
shinyApp(ui = ui, server = server)