-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gs4_auth not working when deploying shiny apps #184
Comments
Can I see the app code anywhere? Have you checked that it's not a path problem? I.e. Also your two snippets are somewhat contradictory. The first one is about googledrive. |
Also, if you are going to move an OAuth token this way, the here is the section that vignette that applies: https://gargle.r-lib.org/articles/non-interactive-auth.html#project-level-oauth-cache That is how you would get a token, locally, interactively, cached to a specific location within your project (Shiny app, in your case). Then deploy it elsewhere. This is NOT how to do it, which looks a bit more like code from the older googlesheets package:
|
Hi, thanks for providing this package! I also ran into issues with auth on shinyapps.io, after following the instructions at https://gargle.r-lib.org/articles/non-interactive-auth.html#project-level-oauth-cache I have credentials stored locally in
But then when trying to have explicit auth via or implicit auth by calling
Calling
which didn't work either. All that server side code is run on the top level of Any hints on how to make this work?
|
I was able to resolve this by creating a service account on the Google developer console and sharing the Google sheets with the service account's email. |
Is this process free or is it a paid service? Thank you for your response! ETA: I looked into Google cloud services, and it appears that credit card information is required even for the free service. I am not comfortable with that. R is free, Googlesheets are free, I am looking for a way to integrate them that does not require my billing information. Thank you for your solution though! I hope it helps the others. |
I don't think you don't have to provide credit card information to get a service account, at least in general. Have you actually tried it @comicalequation? You talk about "Google cloud services" but that's a very broad term and isn't really what we're talking about here. I still think embedding a regular OAuth token within |
I am still in the process of trying out your earlier suggestions (it's taking me a while to understand the mechanisms going on in the link you provided earlier). I will let you know the results when I'm done, along with a demo app code. Thank you for the suggestions!
|
@jennybc I tried your suggestions. Now the application deploys but every time I click on Submit, it says "Disconnected from Server-Reload" and does not save the response. Here is a link to my app: Here is my code:
I have uploaded the .secrets folder to shiny server during deployment. I have checked the google sheet id, it is correct. It works in my RStudio Console and does not need me to authenticate every time after adding the Here is my application log, in case you need it:
I tried replacing
|
I've followed all of these same steps with no luck - still getting the same errors you describe in your first post. To be clear, are you providing the file path to your .json file (ending with something like "project-name-12345678abc1.json")? Or providing the entire json string itself? Or some part of it (e.g., the private_key_id)? |
Have you tried my fix?
Use this for the first time running the app in R to get the OAuth token. When deploying the app to the server, upload this .secrets folder too. Now replace the code above with the code below and upload the app to the server. Use_oob=TRUE is basically what did the trick for me.
|
This is working, thanks. Since I went to the trouble of creating a service account, I was trying to go that route. But a working app is what counts, so thanks! |
Glad to see progress here! In terms of the On the Shiny server, you just want to find and refresh an existing token, which is accomplished by |
When I am not using the |
I note that we have converged exactly on an approach laid out in Non-interactive auth, specifically in the "Project-level OAuth cache" section recommended for deployed data products: So I still feel like this is documented. And that the main thing that would help is an example app (tracked in #158) (?). |
Yes. Your recommendation worked out. Thank you! Issue is resolved! |
I thought I might update this to say that if the scopes are defined in the initial getting of the OAuth token, then they also need to be defined in the server-side code. e.g.
Simply having
causes another attempt to get a token, which breaks on the server. |
Yes, token lookup absolutely includes matching on scopes, so if you're using non-default scopes, they must be fully specified. This is another reason to prefer a service account token over rediscovering a cached oauth token. Quoting from the "non-interactive auth" article:
Note that in the particular scope situation above, getting the token with googledrive might make the most sense. In any case, there is no reason get to Sheets scope and Drive scope. Drive scope implies Sheets scope. See https://googlesheets4.tidyverse.org/articles/articles/drive-and-sheets.html. |
Interestingly, I ALSO had to specify
|
A step that finally worked for me after trying all the things in this thread, and documentation for gargle, googledrive, and googlesheets4, was to go the service account route, yes it is free, and frankly quite useful if you are developing apps. But a step that was required that is not clearly stated anywhere I looked is to go to the Google sheet in question and "Share" it with the email address that is in the JSON key file obtained from the service account. Then it finally worked on my AWS EC2 Ubuntu 18 instance running shiny-server. Finally. This is the last article I read before I got it working: https://robocorp.com/docs/development-guide/google-sheets/interacting-with-google-sheets. I sincerely hope this overlooked step of sharing the JSON key "client_email" address to the Google sheet, giving it Editor permissions, helps someone. |
I have developed a shiny app that works well in my R console. However, when deploying it to shinyio server, I get the following error:
I have read the recommended troubleshooting options, found at https://gargle.r-lib.org/articles/non-interactive-auth.html
What I did was first run the app in my console in a non-interactive session and get the token with the following code:
Then I removed this code and added the following to my app:
According to the gargle link above, providing access to the token file directly should work. However, uploading the app.R file along with the googlesheets_token.rds file both to the shinyio server still keeps producing the same error.
I don't seem to be the only one facing this problem, but I haven't found a solution yet that actually works.
The text was updated successfully, but these errors were encountered: