我一直在尝试编写我的第一个小型闪亮应用程序,它需要两个.xlsx文件并执行inner_join(就像SQL一样),然后让你下载结果.xlsx。但是当我尝试下载文件时,收到错误消息:
Error in path.expand(file) : invalid 'path' argument
Warning: Error in path.expand: invalid 'path' argument
这是我的ui.R:
shinyUI(pageWithSidebar(
headerPanel('A linker'),
sidebarPanel(
fileInput("data","Choose file"),
textInput('d_sheet','Write the name of the sheet to be modified',
value = "", placeholder = "e.g. List 1"),
textInput('d_col','Write the ID-number of column that contains the ID'),
fileInput("libr","Choose library"),
textInput("l_sheet","Write the name of sheet that contains the data",
value="",placeholder="e.g. List 1"),
textInput("l_col","write the ID-number of column that contains the ID"),
textInput("l_join","Write the ID-number of columns to be linked to the
file")
),
mainPanel(
p('This application allows you to link data from the LIBRARY to
the data of the FILE. FILE is the table to be enhanced by the new data,
LIBRARY is the source of the data.'),
downloadButton("dwnld_data",label ="Download"))))
和server.R:
shinyServer( function(input, output){
options(shiny.maxRequestSize = 9*1024^2)
res_file<-reactive({
input_File <- input$data#
file_sheet<-input$d_sheet#
file_col<-as.vector(input$d_col)#
lib_File<-input$libr#
lib_sheet<-input$l_sheet#
lib_col<-as.vector(input$l_col)#
lib_data<-as.vector(input$l_join)#
a_file<-read.xlsx(input_File,sheetName = file_sheet)
colnames(a_file)[1:file_col]<-"a"
colnames(a_file)[file_col:ncol(a_file)]<-"b"
colnames(a_file)[file_col]<-"ID"
l_file<-read.xlsx(lib_File,sheetName=lib_sheet)
tab_l<-l_file[,c(lib_col,lib_data)]
colnames(l_file)<-"ID"
r_file<-inner_join(a_file,l_file,by="ID")
r_file})
output$dwnld_data <- downloadHandler(
filename = function() {paste("result.xlsx")},
content = function(file) {
write.xlsx(res_file(),file, sheetName="List 1")
})})
这没什么特别的,更像是我的第一次实验。我试图找到这个错误的解决方案好几个小时并且发了很多文章,所以我很抱歉,如果我问你一些问题,已经回答了,我还没找到。 我找到并尝试过的所有内容:
感谢您的帮助!