[英]How to get the path from input$.. or output$.. and use it to list.files and then copy/cut the files
我正在学习 Shiny。 我想制作一个简单的应用程序,允许用户输入动态路径。 然后应用程序应列出文件夹 A 中的 csv 文件,然后将它们从文件夹 A 复制到文件夹 B(工作目录)。 然后应用程序使用外部 exe 程序在文件夹 B 中执行一些操作。 之后,该文件夹将从 B 中剪切结果文件 (.txt) 并将它们复制到 A。
我的应用程序的结构如下(我还附上了一张图片)。 该问题在代码中的注释中进行了解释。
library(shiny)
ui<-fluidPage(
textInput("prg","Program",getwd()),
verbatimTextOutput("prg"),
textInput("prj","Project","Project"),
verbatimTextOutput("prj")
)
server<-function(input, output,session) {
output$prg=renderText(input$prg)
renderPrint(output$prg)
output$prj=renderText(paste0(input$prg,"/",input$prj))
#This is where my challenge is
#I want to
#list.files(path=path-shown-in-text-box-Project,pattern=".csv")
#Then i want to copy csv files from A to B as described above and run the following program
#This works
observeEvent(input$run,
{
system("my.exe") #exe not shared
})
#Finally I want to cut and paste the results (.txt) from B back into A
}
shinyApp(ui,server)
我想列出.files(path=path-shown-in-text-box-Project,pattern=".csv")
以下代码可用于浏览特定 CSV 文件的任何目录,读取该文件并显示其内容。
library(shiny)
# Define UI
ui <- pageWithSidebar(
# App title ----
headerPanel("Open a File and Show Contents"),
# Sidebar panel for inputs ----
sidebarPanel(
label="Data Source",fileInput("fileName", "File Name",accept=c(".csv"))),
# Main panel for displaying outputs ----
mainPanel(
tableOutput(outputId = "table")
)
)
# Define server logic
server <- function(input, output) {
inputData <- reactive ({
if (is.null(input$fileName)) return(NULL)
inFile <- input$fileName
conInFile <- file(inFile$datapath,open='read')
inData <- read.csv(conInFile,stringsAsFactors = FALSE)
close (conInFile)
return (inData)
})
output$table <- renderTable ({
inData <- inputData()
if (length(inData) > 0) inData
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.