File size: 4,186 Bytes
f888423 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
box::use(
utils[head, read.csv2],
shiny[div, moduleServer, downloadLink, downloadHandler, sliderInput, tagList, req, reactiveVal, actionButton, fileInput, observeEvent, h1, h3, p, NS, selectizeInput, HTML, tags],
bslib[page_fillable, page_sidebar, nav_panel, page_navbar, layout_columns, card, card_header, card_body, layout_column_wrap, value_box, input_dark_mode, nav_item],
shinyWidgets[pickerInput],
waiter[useWaiter, autoWaiter, waiter_show, spin_fading_circles, waiter_hide, waiterShowOnLoad, waiter_on_busy],
spacyr[spacy_install],
data.table[fread, fwrite],
)
box::use(
view / mod_search_books,
view / mod_recommend_books,
view / mod_data_analysis
)
#' @export
ui <- function(id) {
ns <- NS(id)
page_navbar(
title = "Book Recommender",
sidebar = my_sidebar(ns),
fillable = FALSE,
nav_panel(
useWaiter(),
waiter_on_busy(html = tagList(div(class = "main-waiter", h3("Give me a second to read all those books..."), spin_fading_circles()))),
# waiterShowOnLoad(html = tagList(div(class = "main-waiter", h3("Give me a second to read all those books..."), spin_fading_circles()))),
title = "Recommendations",
tags$main(
class = "main-container",
tags$section(
h1("Discover books you will love!", class = "align-text-center"),
div(class = "text-main align-text-center", p(" Enter books you like and the site will analyse the contents of the books to provide book recommendations and suggestions for what to read next.")),
mod_search_books$ui(ns("search_books")),
mod_recommend_books$ui(ns("recommend_books"))
)
)
),
nav_panel(
"Data analysis",
mod_data_analysis$ui(ns("data_analysis"))
),
# nav_item(
# fileInput(ns("upload_goodreads"), NULL, buttonLabel = "Upload goodreads", multiple = FALSE)
# ),
)
}
#' @export
server <- function(id) {
moduleServer(id, function(input, output, session) {
gargoyle::init("start_recommend_event")
# LOAD DATA ---------------------------------------------------------------
data <- load_data("data/dataset_goodreads_filtered.csv")
item_item_df <- fread("data/item_to_item_similarity_dataframe_full.csv")
user_ratings_tab <- readRDS("data/ratings_filtered.rds")
corp_dfm <- readRDS("data/ref_corp_tfidf_new.rds")
SVD_model <- readRDS("data/svdf.rds")
# spacy_install()
selected_books_ids <- mod_search_books$server("search_books", data$title, data$image_url, data$book_id)
mod_data_analysis$server("data_analysis")
output$downloadData <- downloadHandler(
filename = function() {
"system_recommendations_log.csv"
},
content = function(file) {
data <- fread("system_recommendations_log.csv")
fwrite(data, file)
}
)
observeEvent(input$method, {
mod_recommend_books$server(
"recommend_books",
user_ratings_tab,
SVD_model,
corp_dfm,
item_item_df,
selected_books_ids,
data,
input$how_many_recommends_slider,
input$simil_metrics,
input$method
)
})
observeEvent(input$how_many_recommends_slider, {
mod_recommend_books$server(
"recommend_books",
user_ratings_tab,
SVD_model,
corp_dfm,
item_item_df,
selected_books_ids,
data,
input$how_many_recommends_slider,
input$simil_metrics,
input$method
)
gargoyle::trigger("start_recommend_event")
})
})
}
load_data <- function(path) {
data <- data.table::fread(path)
data[, genres := strsplit(genre, split = ",")]
data[, average_rating := as.numeric(average_rating)]
data$genre <- NULL
data$similar_books <- NULL
return(data)
}
my_sidebar <- function(ns) {
tagList(
sliderInput(ns("how_many_recommends_slider"), "Number of books to recommend", 1, 100, 10, step = 1),
pickerInput(
inputId = ns("method"),
label = "recommendation method",
selected = "ALL",
choices = c("SVD", "TFIDF", "item-item", "ALL")
),
downloadLink(ns("downloadData"), "Download logs")
)
}
|