Browse Source

Stop using sqlite db, everything in-memory, UI with selectize and

autocomplete
master
Maxime Wack 6 years ago
parent
commit
ac50ac40da
2 changed files with 17 additions and 21 deletions
  1. +16
    -17
      app.R
  2. +1
    -4
      preprocess.R

+ 16
- 17
app.R View File

@@ -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) %>%


+ 1
- 4
preprocess.R View File

@@ -1,8 +1,6 @@
library(tidyverse)
library(RSQLite)

imdb <- dbConnect(SQLite(), "imdb.db")

read_tsv("basics.tsv") -> basics
read_tsv("episodes.tsv") -> episodes
read_tsv("ratings.tsv") -> ratings
@@ -27,5 +25,4 @@ tvseries %>%
arrange(seriesTitle, season, episode) ->
final

final %>%
dbWriteTable(conn = imdb, name = "imdb", value = ., overwrite = T)
saveRDS(final, "imdb.rds")

Loading…
Cancel
Save