在上传时复制文件并将其粘贴到 www 文件夹位置
Copying file on upload and paste it to www folder location
我想在 Shiny 中上传文件并将其复制到 WWW 文件夹中。我的代码正在上传文件,但没有将文件复制到 WWW 文件夹位置。我怎样才能做到这一点?我做错了吗?谢谢
以下文件 "ui.R" 也在 www 文件夹中:
library(shiny)
shinyApp(
ui=shinyUI(bootstrapPage(
fileInput("upload", "Upload", multiple = FALSE)
)),
server=shinyServer(function(input, output, session){
observe({
if (is.null(input$upload)) return()
file.copy(input$upload$datapath, "\C:\Users\'XXX XXX'\Documents\R\win-library\3.4\shiny\www\")
})
})
)
相信这是输出路径中提到的字符串的一个简单问题。我能够让下面的代码正常工作。
如果我尝试使用该应用程序上传名为 temp.R 的文件,则该文件将重命名为 0.R 因为在 file.copy
中没有指定完整的文件名。如果您希望它工作而不管用户系统中的名称如何,请提供完整的文件名,例如 file.copy(input$upload$datapath, "C:\NotBackedUp\user_upload.R", overwrite = TRUE)
.
您可以使用 input$upload$name
检索原始名称。
library(shiny)
shinyApp(
ui=shinyUI(bootstrapPage(
fileInput("upload", "Upload", multiple = FALSE)
)),
server=shinyServer(function(input, output, session){
observe({
if (is.null(input$upload)) return()
file.copy(input$upload$datapath,
"C:\NotBackedUp", overwrite = TRUE)
})
})
)
我想在 Shiny 中上传文件并将其复制到 WWW 文件夹中。我的代码正在上传文件,但没有将文件复制到 WWW 文件夹位置。我怎样才能做到这一点?我做错了吗?谢谢
以下文件 "ui.R" 也在 www 文件夹中:
library(shiny)
shinyApp(
ui=shinyUI(bootstrapPage(
fileInput("upload", "Upload", multiple = FALSE)
)),
server=shinyServer(function(input, output, session){
observe({
if (is.null(input$upload)) return()
file.copy(input$upload$datapath, "\C:\Users\'XXX XXX'\Documents\R\win-library\3.4\shiny\www\")
})
})
)
相信这是输出路径中提到的字符串的一个简单问题。我能够让下面的代码正常工作。
如果我尝试使用该应用程序上传名为 temp.R 的文件,则该文件将重命名为 0.R 因为在 file.copy
中没有指定完整的文件名。如果您希望它工作而不管用户系统中的名称如何,请提供完整的文件名,例如 file.copy(input$upload$datapath, "C:\NotBackedUp\user_upload.R", overwrite = TRUE)
.
您可以使用 input$upload$name
检索原始名称。
library(shiny)
shinyApp(
ui=shinyUI(bootstrapPage(
fileInput("upload", "Upload", multiple = FALSE)
)),
server=shinyServer(function(input, output, session){
observe({
if (is.null(input$upload)) return()
file.copy(input$upload$datapath,
"C:\NotBackedUp", overwrite = TRUE)
})
})
)