【发布时间】: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