Geolocation from IP address

I am running a shiny app on and I would like to geolocate the users, ie guess their location so they dont have to enter it manually. I am using the following code:

      # Get IP address
      if(exists(x="HTTP_X_FORWARDED_FOR", envir=session$request)){
        current.ip <- base::get(x="HTTP_X_FORWARDED_FOR", envir=session$request)
      } else {
        current.ip <- ""
      # Get Geolocation
      res  <- GET(paste0("",current.ip,"?access_key=",config::get("ipstackkey")))
      data <- fromJSON(rawToChar(res$content))

If I assign a fixed IP address to current.ip the geolocation works fine. However, I cannot seem to be able to retrieve the user IP.

Any help is welcome!

Best, Wilmar