R 将文本创建区域输入发送到Google云存储
使用R 将文本创建区域输入发送到Google云存储,r,shiny,shinydashboard,shiny-reactivity,R,Shiny,Shinydashboard,Shiny Reactivity,使用googleCloudStorageR包使用*json文件进行身份验证后,我尝试在textAreaInput中写入一个文本,并将其作为*txt发送到我的谷歌云存储桶,但没有成功。输出总是: Listening on http://127.0.0.1:3842 Auto-refreshing stale OAuth token. Warning: Error in : Path 'NA' does not exist [No stack trace available] 我的示例没有我的
googleCloudStorageR
包使用*json文件进行身份验证后,我尝试在textAreaInput
中写入一个文本,并将其作为*txt发送到我的谷歌云存储桶,但没有成功。输出总是:
Listening on http://127.0.0.1:3842
Auto-refreshing stale OAuth token.
Warning: Error in : Path 'NA' does not exist
[No stack trace available]
我的示例没有我的凭据:
# Packages
require(rgdal)
require(shiny)
require(shinythemes)
require(googleCloudStorageR)
# Create the shiny dash
ui <- fluidPage(
theme = shinytheme("cosmo"),
titlePanel(title="My Map Dashboard"),
sidebarLayout(
sidebarPanel(
textAreaInput("text_input","Selected data"),
actionButton("sendMSG", "Send to server")
),
mainPanel(
textOutput("sendMSG")
)
)
)
server <- function(input, output){
MyMSG <- reactive({
output$text_output <- renderText({input$text_input})
})
# Read text write in the box and send to the server
observeEvent(input$sendMSG, {
filename = function() {
paste0("MyText",Sys.Date(),".txt",sep="")
}
content = function(file) {
write.table(MyMSG(), file, row.names = F)
}
# Send output to Google Cloud Storage
gcs_get_bucket("forestcloud")
# *txt files
all_txt_est <- list.files(pattern="\\.txt$", full.names=TRUE)
for(f in 1:length(all_txt_est)){
all_txt_est_name<-all_txt_est[f]
gcs_upload(all_txt_est_name, name=all_txt_est_name)
}
###
})
}
shinyApp(ui, server)
##
#包
需要(rgdal)
需要(有光泽)
需要(发光体)
require(谷歌云存储)
#创造闪亮的破折号
ui可能所有的测试都是空的。您不需要在观测者中执行write.table
函数,只需定义一个执行write.table
的函数,但不使用此函数
不要在无功
导线内定义输出
插槽,这毫无意义
也许以下就是你想要的。我不知道谷歌云存储,所以我不确定代码在这一点上是否正确
server <- function(input, output){
output$sendMSG <- renderText({input$text_input}) # you can do that but this will render the same as the textAreaInput
observeEvent(input$sendMSG, {
filePath <- tempfile(fileext = ".txt")
writeLines(input$text_input, filePath)
# Send output to Google Cloud Storage
gcs_get_bucket("forestcloud")
gcs_upload(filePath, name = filePath)
})
}
服务器很好,谢谢@Stéphane Laurent问题解决!!!