This is an old questions, but I just ran into the same problem using python on ec2 with google sheets and found this question while searching. Here is how I solved it.
Upon trying to connect to google sheets from python, this message popped up:
Please visit this URL to authorize this application:
https://accounts.google.com/o/oauth2/auth?#######
I put the url into my browser on my local machine and selected my Google account for authentication and it got approved. However, the ec2 instance was still stuck.
The url in the browser after authentication changed to a localhost link. I opened up a second connection to the ec2 instance, and using the python requests library, I did
import requests
requests.get(localhost_url_from_browser)
The python script then continued successfully. I'm sure R studio has a library similar to python requests you can use for this.
Note that this does not require the webpage to be publicly accessible.