|
|
@@ -3,7 +3,6 @@ library(plotly) |
|
|
|
|
|
|
|
ui <- fluidPage( |
|
|
|
inputPanel(width = "20%", height = "100%", |
|
|
|
textInput("show_search", "Search show"), |
|
|
|
uiOutput("show_choice") |
|
|
|
), |
|
|
|
plotlyOutput("show_graph", width = "100%", height = "800px") |
|
|
@@ -11,25 +10,26 @@ ui <- fluidPage( |
|
|
|
|
|
|
|
server <- function(input, output, session) |
|
|
|
{ |
|
|
|
shows <- eventReactive(input$show_search, { |
|
|
|
|
|
|
|
if(str_length(input$show_search) > 3) |
|
|
|
{ |
|
|
|
src_sqlite("imdb.db") %>% |
|
|
|
tbl(sql(str_c("select distinct(id), seriesTitle, startYear from imdb where seriesTitle like '%", input$show_search, "%'"))) %>% |
|
|
|
collect %>% |
|
|
|
arrange(desc(startYear)) |
|
|
|
} |
|
|
|
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()) |
|
|
|
|
|
|
|
shows()$id %>% |
|
|
|
setNames(str_c(shows()$seriesTitle, " (", shows()$startYear, ")")) -> |
|
|
|
choices |
|
|
|
|
|
|
|
selectizeInput("show", "Please choose…", choices) |
|
|
|
selectizeInput("show", "Please choose…", shows(), selected = "") |
|
|
|
}) |
|
|
|
|
|
|
|
output$show_graph <- renderPlotly({ |
|
|
@@ -37,8 +37,7 @@ server <- function(input, output, session) |
|
|
|
|
|
|
|
show_id <- input$show |
|
|
|
|
|
|
|
src_sqlite("imdb.db") %>% |
|
|
|
tbl("imdb") %>% |
|
|
|
imdb() %>% |
|
|
|
filter(id == show_id) %>% |
|
|
|
collect %>% |
|
|
|
mutate_at(vars(season, episode, averageRating, numVotes), as.numeric) %>% |
|
|
|