In this blog, you will learn how to easily save user responses in your google spreadsheet in R Shiny. We’ll use mainly the popular shiny package, which contains tags$iframe function to create an inline frame to embed an HTML document in R Shiny application. For more information like common attributes description of iframe check this. This blog also covered how to make google form in your google drive. If anyone has doesn’t make a google form then first create google form and after that connect it to shiny’s application. I hope this is useful to anyone wanting to save user responses in google spreadsheets.
Step 1: Create a form from Google Drive.
When you create a Google Form, it’s saved in Google Drive. To create a form directly from Google Drive:
On a computer, go to the link.
In the top left, click New.
Click More > Google Forms. And make the google form according to your requirement.
4. In Google Forms there are two options in the top middle like Questions and Responses. Click Responses. So you can see below output in your Google Forms.
5. Now, click the green spreadsheet icon in the top right. After that, If you don’t have the existing spreadsheet then select the first option ‘create a new spreadsheet’ and click Create. So when users submit the responses then it will automatically store in the spreadsheet.
6. After completing above steps click the send button in the Google Forms. It shows various options to send form so from that click the link option then you can see the URL of your form. Copy that URL for further use. You can also make the URL short by selecting Shorten URL option.
Step 2: Save user responses using R Shiny.
First, you need to install the shiny package and load the library then you can wrap google form using Shiny's tags$iframe function. After that you can able to display the google form in your application and save the user responses in your spreadsheet.
library(shiny)ui <- shinyUI(navbarPage("App Title",
tabPanel(HTML('<b>','Feedback','</b>'),
tags$iframe(src = 'https://forms.gle/sV7P5xhcLwcHvbPU8',
width = '100%',
height = 500,
frameborder = 0,
marginheight = 0)
)
))server <- function(input, output, session) {
}shinyApp(ui, server)
Note that when you run the app locally, you must use “Open in Browser” to see the embedded Google Form!
Comments