Search code examples
rshinyggmapgeocode

geocode from ggmap fails on shiny server


I have an app where the user can provide a specific address and the app returns the geocode which is later used to subset the data.

The snippet of the code is as simple as:

library(ggmap)
geocode("2020 walnut street pa")

This works perfectly when I run it on my local machine. I get the below output:

Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2020%20walnut%20street%20pa&sensor=false
        lon      lat
1 -75.17508 39.95034

However when I run this same code on the shiny server, I get the below error:

> library(ggmap)
Loading required package: ggplot2
> geocode("2020 walnut street pa")
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2020%20walnut%20street%20pa&sensor=false
  lon lat
1  NA  NA
Warning messages:
1: In readLines(connect, warn = FALSE) :
  URL 'http://maps.googleapis.com/maps/api/geocode/json?address=2020%20walnut%20street%20pa&sensor=false': status was 'Couldn't connect to server'
2: In geocode("2020 walnut street pa") :
    geocoding failed for "2020 walnut street pa".
  if accompanied by 500 Internal Server Error with using dsk, try google.
> 

I guess this is related to some permission issue but I have no idea on what needs to be done. Can anyone help me understand what needs to be done here?


Solution

  • I was able to find a solution to this. In the shiny app (global.R), I set

    Sys.setenv(http_proxy="http://corp.com:8080")
    

    This resolved the proxy issue and server was able to connect with the google api.