r - 将 textAreaInput 中的文本创建发送到 Google Cloud Storage
问题描述
在使用googleCloudStorageR
包使用 *json 文件进行身份验证后,我尝试在 a 中写入文本textAreaInput
并作为 *txt 发送到我的 Google Cloud Storage 存储桶,但没有成功。输出总是:
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)
##
请帮忙解决一下?
解决方案
大概all_txt_est
是空的。您不在write.table
观察者中执行该函数,您只需定义一个执行的函数write.table
,但您不使用此函数。
不要在导体output
内部定义槽reactive
,这没有任何意义。
也许以下是您想要的。我不了解谷歌云存储,所以我不确定关于这一点的代码是否正确。
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)
})
}
推荐阅读
- ios - 从单独的应用程序目标加载 XIB
- python - Python指定文件位置目录
- reverse-engineering - 使用 Ollydbg 修改内存
- apache-spark - 如何将配置从 spark-submit 传递到纱线集群?
- search - NetSuite 保存的销售订单子列表搜索(相关记录)
- swift - 尤里卡表单不显示
- sql - 编码 ASP.NET Core 和 SQL Server 的问题
- git - 强制推送 git 预接收挂钩错误
- sas - 将导入的文件名捕获到 SAS 中的变量中
- arrays - 允许用户通过图片框快速循环 100 多张图像的最有效方法是什么