shinyapps.io: data from API (read_lines())

Hi,

I'm new to shiny. My first project is to build an app that displays the NBA scores for a user selected date. It works perfectly when I run it on a local machine but does not work when I deploy to shinyapps.io.

I debugged it so far that I found what is not working. Apparently the app does not read the data from the NBA API.

Here is a code sample of what I'm doing:

library(shiny)
library(tidyverse)
library(lubridate)
library(glue)

ui <- fluidPage(

  # Application title
  titlePanel("Get NBA Scores"),

  # Select date
  sidebarLayout(
    sidebarPanel(
      dateInput(inputId = "date",
                label = "Select Date")
    ),

    mainPanel(
      textOutput("boxscores")
    )
  )
)

server <- function(input, output) {

  date <- reactiveValues()
  url <- reactiveValues()
  nba <- reactiveValues()

  # add leading zero to day
  observe(date$day <- ifelse(nchar(day(as.character(input$date))) == 1, paste0("0", day(as.character(input$date))), day(as.character(input$date))))

  # add leading zero to month
  observe(date$month <- ifelse(nchar(month(as.character(input$date))) == 1, paste0("0", month(as.character(input$date))), month(as.character(input$date))))

  # extract year
  observe(date$year <- year(as.character(input$date)))

  # create url
  observe(url$url1 <- glue("http://stats.nba.com/stats/scoreboard/?GameDate={date$month}/{date$day}/{date$year}&LeagueID=00&DayOffset=0"))

  #import data
  observe(nba$nba <- read_lines(url$url1))

  output$boxscores <- renderText({
    #plot raw data
    nba$nba
  })     
}

# Run the application 
shinyApp(ui = ui, server = server)

When I just want to display the url using

output$boxscores <- renderText({
  #plot url
  url$url1
})  

it works fine. But when I want to get the external data it does not show anything (not even an error).

Am i doing something wrong? Or is it not possible to read external data on shinyapps.io?

Thanks for your help.

Yes it is possible to read external data from shinyapps.io.

However, shinyapps.io is hosted in AWS, and from I am reading, NBA stats is explicitly blocking AWS IP addresses. Sorry I don't have better news.

Thanks for the information.
Then I will think of another way to build this app.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.