【问题标题】:Use Shiny to collect data from users in Google Sheet在 Google Sheet 中使用 Shiny 从用户那里收集数据
【发布时间】:2020-06-19 23:12:34
【问题描述】:

我想使用 Shiny 界面从用户输入中收集数据,例如 Medium Article

本文是为 googlesheets 包编写的,但我们现在需要使用 googlesheets4。

我认为我的代码将无法工作,因为可能对反应元素有一定的理解。

#load libraries
library(shiny)
library(shinydashboard)
library(googlesheets4)
library(DT)

ui <- fluidPage(

    # Define UI
    ui <- fluidPage(
        # App title ----
        titlePanel("Seflie Feedback"),
        # Sidebar layout with input and output definitions ----
        sidebarLayout(
            # Sidebar to demonstrate various slider options ----
            sidebarPanel(
                # Input: Overall Rating
                sliderInput(inputId = "helpful", 
                            label = "I think this app is helpful",
                            min = 1, 
                            max = 7,
                            value = 3),
                actionButton("submit", "Submit")
            ),
            mainPanel(
            ))
    )
)
server <- function(input, output, session) {
    # Reactive expression to create data frame of all input values ----
    sliderValues <- reactive({

        usefulRating <- input$helpful

        Data <-  data.frame(
            Value = as.character(usefulRating),
            stringsAsFactors = FALSE)
    })

    #This will add the new row at the bottom of the dataset in Google Sheets.
    observeEvent(input$submit, { 
         MySheet <- gs4_find() #Obtain the id for the target Sheet
        MySheet <-   gs4_get('https://docs.google.com/spreadsheets/d/162KTHgd3GngqjTm7Ya9AYz4_r3cyntDc7AtfhPCNHVE/edit?usp=sharing')
        sheet_append(MySheet , data = Data)
    })
}
shinyApp(ui = ui, server = server)

我将 gs4_get() 替换为链接而不是 ID,以支持您帮助我。如果您无法访问该链接,您可以暂时将链接替换为您自己工作表中的 Google 工作表 ID。

当我运行代码时,我看到以下内容:警告:is.data.frame 中的错误:找不到对象“数据”。 当我将有用Rating

感谢您的任何见解:)

【问题讨论】:

    标签: r google-sheets shiny googlesheets4


    【解决方案1】:
    #load libraries
    library(shiny)
    library(shinydashboard)
    library(googlesheets4)
    library(DT)
    
        ui <- fluidPage(
            titlePanel("Seflie Feedback"),
            sidebarLayout(
                sidebarPanel(
                    #This is where a user could type feedback
                    textInput("feedback", "Plesae submit your feedback"),
               ),
                    #This for a user to submit the feeback they have typed
                     actionButton("submit", "Submit")),
                mainPanel())
    
    server <- function(input, output, session) {
        
        textB <- reactive({
    
             as.data.frame(input$feedback)
    
            })
        
        observeEvent(input$submit, {
            Selfie <-   gs4_get('https://docs.google.com/spreadsheets/d/162KTHgd3GngqjTm7Ya9AYz4_r3cyntDc7AtfhPCNHVE/edit?usp=sharing')
            sheet_append(Selfie, data = textB())
        })
    }
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 2016-12-18
      • 2017-09-22
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多