title: Connect to googlesheets via shiny in R with googlesheets4
body: <p>I'm trying to use an updated version of this <a href="https://github.com/jennybc/googlesheets/blob/master/inst/shiny-examples/10_read-write-private-sheet/global.R" rel="noreferrer">example</a> to connect to a private googlesheet via shiny, and deploy this app on the shinyapps.io server. The user is not required to authenticate to a google account as the app uses a specified pre-existing googlesheet.</p>
  <p>I've followed this <a href="https://github.com/jennybc/googlesheets/blob/master/inst/shiny-examples/10_read-write-private-sheet/global.R" rel="noreferrer">example</a> (partly copied here), attempting to save the token to my shiny app:</p>
  <pre><code># previous googlesheets package version:
  shiny_token &lt;- gs_auth() # authenticate w/ your desired Google identity here
  saveRDS(shiny_token, &quot;shiny_app_token.rds&quot;)
  
  </code></pre>
  <p>but tried to update it to googlesheets4, like this:</p>
  <pre><code>ss &lt;- gs4_get(&quot;MY GOOGLE DOC URL&quot;) # do the authentication once, manually.
  ss
  gs4_has_token() # check that the token exists
  
  # get token
  ss_token &lt;- gs4_token()
  # save the token
  save(ss_token, file = &quot;APP PATH ... /data/tk.rdata&quot;)
  </code></pre>
  <p>Then in the app, I have placed this code outside the <code>shinyApp()</code> function.</p>
  <pre><code>load(&quot;data/tk.rdata&quot;)
  
  googlesheets4::gs4_auth(token = ss_token, use_oob = T)
  </code></pre>
  <p>In the app, I connect to a google doc from the app, using a hardcoded id obtained from
  <code>ss$spreadsheet_id</code> above. The app works locally.</p>
  <p>After attempting to deploy the app to the server I get the error &quot;...Can't get google credentials. Are you running googlesheets4 in a non-interactive session?... etc&quot; I thought that the token would contain sufficient information for this.</p>
  <p>I'd be grateful if anyone can point me to a guide to setting this up, and also comment on whether this approach (saving a token on the shinyapps.io) is safe?</p>
  <p>I've looked at other examples, but it seems most are for the previous version of <code>googlesheets</code></p>