A graphTV clone
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4KB

  1. library(tidyverse)
  2. library(plotly)
  3. readRDS("imdb.rds") -> imdb
  4. imdb %>%
  5. distinct(id, .keep_all = T) %>%
  6. mutate(title = str_c(seriesTitle, " (", startYear, ")")) %>%
  7. select(id, title) -> shows
  8. shows$id %>%
  9. setNames(shows$title) -> shows
  10. shows <- shows[- (names(shows) %>% is.na %>% which)]
  11. ui <- fluidPage(
  12. inputPanel(width = "20%", height = "100%",
  13. h1("GraphTV"),
  14. selectizeInput("show", "Search show", shows, selected = "tt0944947", width = "600px")
  15. ),
  16. plotlyOutput("show_graph", width = "100%", height = "800px")
  17. )
  18. server <- function(input, output, session)
  19. {
  20. output$show_graph <- renderPlotly({
  21. req(input$show)
  22. show_id <- input$show
  23. imdb %>%
  24. filter(id == show_id) %>%
  25. by(.$season, function(x){
  26. fit <- lm(averageRating ~ episode, data = x)
  27. x %>%
  28. plot_ly(hoverinfo = "text",
  29. text = ~str_c("S", season, "E", episode, " - ", episodeTitle, "<br>",
  30. "Rating: ", averageRating, " (", numVotes, " votes)<br>")) %>%
  31. add_trace(data = x, x = ~episode, y = ~averageRating, mode = "markers") %>%
  32. add_trace(data = x, x = ~episode, y = fitted(fit), mode = "lines") %>%
  33. layout(xaxis = list(tick0 = 0, dtick = 1),
  34. yaxis = list(title = "Rating"))
  35. }) %>%
  36. subplot(shareY = T, nrows = 1, margin = 0) %>%
  37. hide_legend
  38. })
  39. }
  40. shinyApp(ui = ui, server = server)