Shiny App runs locally but does not run once deployed: All packages loaded, cannot find where the issue lies!

Hi all!

You all helped me out with my previous question so I was hoping to ask something similar.

I currently have an app that 'generates' recommendations for music, games, books, and tv. However, the books portion just does not seem to work.

Originally, I thought it might have been that the rvest scraping was too taxing but I don't think that is the issue.

I can run the app locally as many times as I wish, but once deployed I keep seeing that there was an error.

Any help would be greatly appreciated.

My reprex is below!

library(shiny)
library(tidyverse)
library(stringr)
library(stringi)
library(rvest)
#> Loading required package: xml2
#> 
#> Attaching package: 'rvest'
#> The following object is masked from 'package:purrr':
#> 
#>     pluck
#> The following object is masked from 'package:readr':
#> 
#>     guess_encoding
library(purrr)
library(collapsibleTree)
library(shinycssloaders)
library(dplyr)
library(forcats)

search_this <- function(x){
    # Fake a search query 
    x <- 
        ifelse(
            str_detect(x, " "),
            paste0("https://www.goodreads.com/search?q=",
                   str_replace_all(x, " ", "+")),
            paste0("https://www.goodreads.com/search?q=", 
                   x)
        )
    x <- 
        x %>% 
        read_html() %>% 
        html_nodes("table a") %>% 
        html_attr("href") %>% 
        .[1]
    # get link to book title
    x <- paste0("https://www.goodreads.com",x)
    x
}

##################FUNCTION NEW#####################
get_gp_link <- function(url){
    # get recommendation links
    gp_rec_links <- 
        url %>% 
        read_html() %>% 
        html_nodes(".cover a") %>% 
        html_attr("href")
} 
################FUNCTION NEW#####################
get_p_rec_name <- function(urls){
    # get names of recommendations
    book_rec_names <- 
        urls %>% 
        read_html() %>% 
        html_nodes(".cover img") %>% 
        html_attr("alt")
    book_parent_title <- 
    # get titles of parent books
        urls %>% 
        read_html() %>% 
        html_nodes("#bookTitle") %>% 
        html_text(trim = T)
    data.frame(book_parent_title,
               book_rec_names)
}
ui <- 
    fluidPage(
    titlePanel("GoodReads: Readers Also Liked",
               windowTitle = "BookRecs"),
    p("A tool for you to find your next book!"),
    tags$a(href="https://www.goodreads.com/","All reccomendations sourced from GoodReads."),
    br(),
    hr(),
    sidebarLayout(
        sidebarPanel(
            textInput(
                inputId = "book_title",
                label = "Name of Book",
                placeholder = NULL,
                width = "325px"
            ),
            actionButton("search_book_title",
                         "Search Book Title",
                         icon = icon("book")),
            br(),
            br(),
            em("Note: This will take around 1 minute to process."),
        ),
        mainPanel(
            collapsibleTreeOutput("book_text")
        ),
        position = c("left", "right")
    )
)
server <- function(input, output) {
######################Book Recommendations#################
x_book_title <- eventReactive(input$search_book_title, {
    input$book_title
})
# Create function for text to render
output$book_text <- renderCollapsibleTree({
    # Replace " " with "+"
    gr_link <- 
        search_this(x_book_title())
    book_name <-   
        gr_link %>% 
        read_html() %>% 
        html_nodes("#bookTitle") %>% 
        html_text(trim=T)

    #
    new_links <- get_gp_link(gr_link)
    book_tree <- map_df(new_links,get_p_rec_name)
    #Create Tree
    collapsibleTree(
        book_tree,
        hierarchy = c("book_parent_title",
                      "book_rec_names"),
        root = paste0(book_name)
    )
    })
}




shinyApp(ui, server)
#> 
#> Listening on http://127.0.0.1:8403

Created on 2020-08-14 by the reprex package (v0.3.0)

Hi @DaveBrock92, did you check the log files on shinyapps.io?
You might want to add the tag shinyapps.io to your post

Hi @ginberg!

I actually was unaware of the logs in the first place. I wanted the site to work with the three other mediums, so I commented out the books section. I will add it back in now and take a look at the logs.

Thank you for the suggestion, I've added the shinyapps.io tag!

Edit: I have attached the logs, if you I am forgetting something please let me know and I will supply it ASAP!

If I had to guess, the 403 response status indicates that Goodreads doesn't allow this sort of access from AWS, where shinyapps.io is hosted. If you want to use their API, they would like you to register for a developer key.

Hi Josh,

Thank you for the reply!

That is what I was thinking as well. I think it might be the volume or requests I am making. I had another section which would pull a quote from the book entered, but that was one request--compared to the ~324 requests the current state makes.

I looked into their API, but they do not seem to have a function that houses the similar books.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.