Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 1c99801

Browse files
author
jennybc
committedJun 30, 2015
add an app that reads/writes a private sheet
how did we not have one of these already? [skip ci]
1 parent ecf6280 commit 1c99801

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ README.html
1010
pics
1111
jenny_token.rds
1212
rsconnect
13+
shiny_app_token.rds
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
library(shiny)
2+
library(googlesheets)
3+
4+
shinyServer(function(input, output, session) {
5+
6+
observeEvent(
7+
input$reset,
8+
gs_edit_cells(ss, input = filler)
9+
)
10+
observeEvent(
11+
input$submit,
12+
gs_edit_cells(ss, input = input$contents,
13+
## the +1 business is to avoid writing into the header row
14+
anchor = cell_limits(c(input$row + 1, input$column),
15+
c(input$row + 1, input$column)))
16+
)
17+
the_data <- eventReactive({input$submit | input$reset},
18+
gs_read(ss), ignoreNULL = FALSE)
19+
output$table <- renderTable(the_data())
20+
21+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
library(shiny)
2+
library(shinythemes)
3+
4+
shinyUI(
5+
fluidPage(
6+
theme = shinytheme("cosmo"),
7+
titlePanel("Read and write a private Google Sheet"),
8+
sidebarLayout(
9+
sidebarPanel(
10+
h6(paste("This app is hard-wired to target a private Google Sheet.")),
11+
h6(paste("You can't visit the Sheet in the browser, because it's",
12+
"private. Which is the whole point of this example.")),
13+
h6("Fail to browse the Sheet: ",
14+
a("HERE", href = ss$browser_url, target="_blank")),
15+
h6(a("Click Here to See Code on Github",
16+
href="https://github.com/jennybc/googlesheets/tree/master/inst/shiny-examples/10_read-write-private-sheet",
17+
target="_blank")),
18+
sliderInput("row", "Row", min = 1, max = n, value = 1, step = 1,
19+
ticks = FALSE),
20+
selectInput("column", "Column",
21+
choices = setNames(seq_len(n), colnames(filler))),
22+
selectInput("contents", "Cell contents",
23+
choices = c("apple", "grape", "banana")),
24+
actionButton("submit", "Submit", class = "btn-primary"),
25+
actionButton("reset", "Reset", class = "btn-primary")
26+
),
27+
mainPanel(
28+
tableOutput("table")
29+
)
30+
)
31+
))

‎inst/shiny-examples/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ We've built a few simple apps to get you started in some important use cases:
2626
- [03_craigslist-lost-and-found](03_craigslist-lost-and-found): reads from a public spreadsheet that utilizes the Google Sheet function `IMPORTXML` to read data from Vancouver's Craigslist's Lost and Found listings. See it deployed [here](https://jennybc.shinyapps.io/03_craigslist-lost-and-found).
2727
- [04_embedded-google-form](04_embedded-google-form): a Google Form is embedded in the app, allowing user to enter data with native Google Form/Sheets functionality. App also displays the underlying Sheet, allowing user to see the just-entered data. See it deployed [here](https://jennybc.shinyapps.io/04_embedded-google-form).
2828
* Credentials are baked into the app:
29-
- *make one of these!*
29+
- [10_read-write-private-sheet](10_read-write-private-sheet): app users are allowed to view and edit data in a private Google Sheet via the app. A token stored in a file within the app is used for auth. See it deployed [here](https://jennybc.shinyapps.io/10_read-write-private-sheet).
30+
- See [Persistent data storage in Shiny apps](http://deanattali.com/blog/shiny-persistent-data-storage), a blog post by [Dean Attali](http://deanattali.com), for another example of using a Google Sheet as a Shiny data store. He shows how to append new rows to a data table. His app loads the token from the cache in a `.httr-oauth` file.
3031
* User provides Google credentials via the app:
3132
- [20_gs-explorer](20_gs-explorer): app requires the user to authenticate with Google and authorize the app to deal on their behalf. After authorization, the user is presented with a listing of their Sheets, the option to view details of each spreadsheet and inspect the worksheets contained in a spreadsheet.
3233

33-
Dean Attali also includes a Google Sheets + `googlesheets` example in his blog post [Persistent data storage in Shiny apps](http://deanattali.com). *not published yet but will be soon*
34-
3534
## More inspiration for feeding Google Sheets:
3635

3736
Here are examples of using Google Sheets as an online datastore from Amit Argawal's [blog](http://www.labnol.org/tag/guide/):

0 commit comments

Comments
 (0)
This repository has been archived.