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.

48 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. ui <- fluidPage(
  11. inputPanel(width = "20%", height = "100%",
  12. h1("GraphTV"),
  13. selectizeInput("show", "Search show", shows, selected = "tt0944947", width = "600px")
  14. ),
  15. plotlyOutput("show_graph", width = "100%", height = "800px")
  16. )
  17. server <- function(input, output, session)
  18. {
  19. output$show_graph <- renderPlotly({
  20. req(input$show)
  21. show_id <- input$show
  22. imdb %>%
  23. filter(id == show_id) %>%
  24. by(.$season, function(x){
  25. fit <- lm(averageRating ~ episode, data = x)
  26. x %>%
  27. plot_ly(hoverinfo = "text",
  28. text = ~str_c("S", season, "E", episode, " - ", episodeTitle, "<br>",
  29. "Rating: ", averageRating, " (", numVotes, " votes)<br>")) %>%
  30. add_trace(data = x, x = ~episode, y = ~averageRating, mode = "markers") %>%
  31. add_trace(data = x, x = ~episode, y = fitted(fit), mode = "lines") %>%
  32. layout(xaxis = list(tick0 = 0, dtick = 1),
  33. yaxis = list(title = "Rating"))
  34. }) %>%
  35. subplot(shareY = T, nrows = 1, margin = 0) %>%
  36. hide_legend
  37. })
  38. }
  39. shinyApp(ui = ui, server = server)