From 61564a33edb1d7301c1741ccc421154cb8597665 Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Wed, 3 Jan 2018 23:45:36 +0100 Subject: [PATCH] Static data and restart on update --- app.R | 37 +++++++++++++------------------------ dl_imdb.sh | 8 ++++++++ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app.R b/app.R index f24dc9b..fe77605 100644 --- a/app.R +++ b/app.R @@ -1,43 +1,32 @@ library(tidyverse) library(plotly) +readRDS("imdb.rds") -> imdb + +imdb %>% + distinct(id, .keep_all = T) %>% + mutate(title = str_c(seriesTitle, " (", startYear, ")")) %>% + select(id, title) -> shows + +shows$id %>% + setNames(shows$title) -> shows + ui <- fluidPage( inputPanel(width = "20%", height = "100%", - uiOutput("show_choice") + h1("GraphTV"), + selectizeInput("show", "Search show", shows, selected = "tt0944947", width = "600px") ), plotlyOutput("show_graph", width = "100%", height = "800px") ) server <- function(input, output, session) { - imdb <- reactive({ - readRDS("imdb.rds") - }) - - shows <- reactive({ - req(imdb()) - - imdb() %>% - distinct(id, .keep_all = T) %>% - mutate(title = str_c(seriesTitle, " (", startYear, ")")) %>% - select(id, title) -> shows - - shows$id %>% - setNames(shows$title) - }) - - output$show_choice <- renderUI({ - req(shows()) - - selectizeInput("show", "Please choose…", shows(), selected = "") - }) - output$show_graph <- renderPlotly({ req(input$show) show_id <- input$show - imdb() %>% + imdb %>% filter(id == show_id) %>% collect %>% mutate_at(vars(season, episode, averageRating, numVotes), as.numeric) %>% diff --git a/dl_imdb.sh b/dl_imdb.sh index e3241aa..56a0a49 100755 --- a/dl_imdb.sh +++ b/dl_imdb.sh @@ -1,3 +1,11 @@ +cd /srv/shiny/GraphTV + curl https://datasets.imdbws.com/title.basics.tsv.gz | gzip -d | cut -f 1-3,6 | sed 's/"/\\"/g' > basics.tsv curl https://datasets.imdbws.com/title.ratings.tsv.gz | gzip -d > ratings.tsv curl https://datasets.imdbws.com/title.episode.tsv.gz | gzip -d > episodes.tsv + +Rscript preprocess.R + +rm *.tsv + +touch restart.txt