[英]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.