【发布时间】:2019-04-30 12:50:16
【问题描述】:
我的应用程序允许用户输入日期范围、部门、pdf 文件和 excel 文件。该程序从 pdf 中提取数字,计算总分,并将其添加到从现有 excel 文件中提取的排名中。它应该写入并保存excel文件。没有 Shiny,我的程序运行良好。在 Shiny 中,它正在运行并且数据是正确的,但它不会将数据添加到 excel 文件中。我在各个阶段添加了打印提示来测试这一点。我也尝试过在外部运行它,结果相同。它不会抛出错误,只是不会将数据添加到 excel 文件中。
服务器功能
server<-function(input,output){
output$horse_div <- renderText({
paste("You have chosen",input$division)
})
output$qualifying<-renderText({
paste("Qualifying Period from",input$date[1],"to",input$date[2])
})
output$pdf<-renderText({
req(input$horsereport)
req(input$excelfile)
ponyoutput<-horseRecord(input$horsereport$datapath,input$date[1],input$date[2],input$division,input$excelfile$datapath)
paste("mylist",ponyoutput[1])
})
}
horseRecord 函数片段
#Set up sheet and excel file
wsheetrank<-paste(div,"RANK")
wsheetpoints<-paste(div,"POINTS")
#load workbook
wb<-loadWorkbook(file=excelfile)
#add pony to ranked list
rank<-read.xlsx(excelfile,wsheetrank)
rank<-rank[,2:3]
rank<-rank %>% mutate(Points=as.numeric(Points))
dat<-rank
dat<-dat%>% add_row(Pony=horse,Points=points) %>% arrange(desc(Points))
#remove duplicates
dat<-dat[!duplicated(dat$Pony),]
rownames(dat)<-seq(from=1,to=nrow(dat),by=1)
#find rank
rank<-grep(horse,dat$Pony)
#Write to excel file
writeData(wb,sheet=wsheetrank,x=dat,colNames=TRUE,rowNames = TRUE,borders="all")
saveWorkbook(wb,excelfile,overwrite=TRUE)
这应该将从 PDF 文件中提取的总分添加到排名列表中,然后再写入排名工作表。完整的代码和文件可以在这里找到:https://github.com/chealy21/horsePoints
【问题讨论】:
-
第一个问题很好!下一次,请发布一个最小且可重现的示例。在这种情况下,您可以通过 10 行代码下的自包含示例来说明您的问题。它不一定是真实数据:)