【发布时间】:2021-06-21 00:03:38
【问题描述】:
我需要“发送”按钮将所有应用信息发送到保存在 Google 云端硬盘中的电子表格(不仅仅是第一个信息);每个列(姓名,年龄,出生...)。谢谢!
这是我的代码:
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(googlesheets4)
library(googledrive)
library(readr)
library(DT)
# Dashboard
ui <- dashboardPage(skin = "red",
dashboardHeader(
title = "Controller"
),
dashboardSidebar(
sidebarMenu(
menuItem(
"Home",
tabName = "home",
icon = icon("home"))
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "home", h2("Hello"),
br(),
box(
h2(icon("id-card"), "Client"),
width = 2000,
br(),
# Insery name
textInputIcon(
inputId = "name",
label = "Name"),
# Birth
dateInput(
inputId = "dob",
label ="Birth",
min = "1960-01-01",
max = Sys.Date(), format = "yyyy/mm/dd",
language = "en"),
textInputIcon(
inputId = "age",
label = "Age"),
# Phone
textInputIcon(
inputId = "phone",
label = "Phone"),
# E-mail
textInputIcon(
inputId = "email",
label = "E-mail"),
# Send
actionButton("send", "Send"),
)
)
)
)
)
# Server
server <- function(input, output, session) {
textname <- reactive({
as.data.frame(input$name)
})
observeEvent(input$sendname, {
Selfie <- gs4_get('link')
sheet_append(Selfie, data = textname())
})
observe({ dob <- input$dob
if(!is.null(dob)) {
days <- as.integer((Sys.Date() - as.Date(dob)))
years <- as.integer(days / 365)
months <- as.integer((days %% 365 ) / 30)
age <- paste(years, 'year(s)', months, 'month(s)')
#print(age)
updateTextInput(session, "age", value = age)
}
})
}
# App
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r google-sheets shiny google-drive-api