Shiny 正在尝试将闪亮应用程序数据(csv)写入桌面上的文件夹。警告:文件中有错误:无法打开连接
我是shiny的新手,正在尝试创建一个调查,在那里提交的数据将下载到我桌面上的一个文件夹中 我使用本文作为指导,基本上有完全相同的代码,但使用了“本地存储”选项来保存数据 当我运行应用程序时,文件被保存到我桌面上的正确文件夹中,但当我在shinyapps.io上发布并尝试使用url提交响应时,我收到错误: 文件中的警告(文件,ifelse(附加“a”、“w”) 和 无法打开文件“C:/Users/tolson/Desktop/shinny/1524841166_57edadaa8d9c46a94f5bb4a352412699.csv”:没有这样的文件或目录 2018-04-27T14:59:26.847383+00:00 shinyapps[331397]:警告:文件错误:无法打开连接 这与shiny的写作权限有关吗?我已经花了大量时间进行研究,但运气不好。任何帮助或见解都将不胜感激。提前谢谢Shiny 正在尝试将闪亮应用程序数据(csv)写入桌面上的文件夹。警告:文件中有错误:无法打开连接,shiny,Shiny,我是shiny的新手,正在尝试创建一个调查,在那里提交的数据将下载到我桌面上的一个文件夹中 我使用本文作为指导,基本上有完全相同的代码,但使用了“本地存储”选项来保存数据 当我运行应用程序时,文件被保存到我桌面上的正确文件夹中,但当我在shinyapps.io上发布并尝试使用url提交响应时,我收到错误: 文件中的警告(文件,ifelse(附加“a”、“w”) 和 无法打开文件“C:/Users/tolson/Desktop/shinny/1524841166_57edadaa8d9c46a94
Code:
library(shiny)
# Define the fields we want to save from the form
fields <- c("name", "dog", "food")
# Save a response
# ---- This is one of the two functions we will change for every storage
type ----
saveData <- function(data) {
data <- as.data.frame(t(data))
if (exists("responses")) {
responses <<- rbind(responses, data)
} else {
responses <<- data
}
代码:
图书馆(闪亮)
#定义要从表单保存的字段
shinyapps.io上的服务器不能只将文件写入您的桌面。但是,您可以使用Dropbox,如所述。谢谢@GregordeCillia,非常感谢。
# Load all previous responses
# ---- This is one of the two functions we will change for every storage
type ----
loadData <- function() {
if (exists("responses")) {
responses
}
}
# Shiny app with 3 fields that the user can submit data for
shinyApp(
ui = fluidPage(
DT::dataTableOutput("responses", width = 300), tags$hr(),
textInput("name", "Name", ""),
textInput("dog", "what is your favorite dog?"),
textInput("food", "favorite food?"),
actionButton("submit", "Submit")
),
server = function(input, output, session) {
# Whenever a field is filled, aggregate all form data
formData <- reactive({
data <- sapply(fields, function(x) input[[x]])
data
})
# When the Submit button is clicked, save the form data
observeEvent(input$submit, {
saveData(formData())
})
# Show the previous responses
# (update with current response when Submit is clicked)
output$responses <- DT::renderDataTable({
input$submit
loadData()
})
outputDir <- "C:/Users/tolson/Desktop/Shiny"
saveData <- function(data) {
data <- t(data)
# Create a unique file name
fileName <- sprintf("%s_%s.csv", as.integer(Sys.time()),
digest::digest(data))
# Write the file to the local system
write.csv(
x = data,
file = file.path(outputDir, fileName),
row.names = FALSE, quote = TRUE
)
}
loadData <- function() {
# Read all the files into a list
files <- list.files(outputDir, full.names = TRUE)
data <- lapply(files, read.csv, stringsAsFactors = FALSE)
# Concatenate all data together into one data.frame
data <- do.call(rbind, data)
data
}
}
)