thank you @andresrcs for answering. Here is my code:
table <- "responses"
SHEET_ID <- c('1E7JX1_oU0--FXk0FfV0ZrBT38_MJoqvnMI4w3G-ZUxQ')
saveData <- function(data) {
# The data must be a dataframe rather than a named vector
data <- data %>% as.list() %>% data.frame()
# Add the data as a new row
sheet_append(SHEET_ID, data)
}
loadData <- function() {
# Read the data
read_sheet(SHEET_ID)
}
fields <- c("name", "comments", "portfolio")
gs4_deauth()
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel(
h3("Reserve Analysis"),
fluidRow(
column(4,
h5("Add your comment"),
textInput("name", "Name"),
selectInput("portfolio", "Portfolio", unique(df_long$Portfolio)),
textAreaInput("comments", "Add your comment", row = 5),
actionButton("submit", "Submit")
),
#there are some other code, but they work without problem
...
server <- function(input, output, session) {
# It is only problematic code
formData <- reactive({
data <- sapply(fields, function(x) input[[x]])
data
})
observeEvent(input$submit, {
saveData(formData())
})
output$responses <- DT::renderDataTable({
input$submit
loadData()
})
shinyApp(ui = ui, server = server)
here is picture of problem:
thanks in advance!