我无法将csv文件从闪亮传递到RMD。请不要再提及其他帖子,因为所有帖子都经过了

时间:2018-11-26 21:48:15

标签: r shiny r-markdown

用户上传3个数据集->应用程序对其进行清理->用户下载已清理的数据->将已清理的数据上传到报告生成器->正在生成报告(HTML格式)。清洁零件并下载清洁的数据可以正常工作。一切都在#REPORT GENERATOR之上。

Server.R

library("shiny")

ShinyServer(function(input, output) {
data <- reactive({
infile <- input$clin #clin file
if(is.null(infile)){
  #use has not upload it yet
  return(NULL)}
table <- read.csv(file=infile$datapath,sep = ",")
return(table)
})
#data for Cree completed 
data2 <- reactive({
infile2 <- input$completedCree #Cree completed visits
if(is.null(infile2)){
  #use has not upload it yet
  return(NULL)}
table2 <- read.csv(file=infile2$datapath,sep = ",")
return(table2)
})
#data for Mul completed 
data3 <- reactive({
infile3 <- input$completedMul 
if(is.null(infile3)){
  #use has not upload it yet
  return(NULL)}
table3 <- read.csv(file=infile3$datapath,sep = ",")
return(table3)
})
buttonClicked <- eventReactive(input$clean, {
shinyalert::shinyalert("Warning!", "This process may take up to 3 
minutes", type = "info")
clean_data(data(),data2(),data3())
})
output$text <- renderText({
"Click Download! Make sure the file has been successfully downloaded 
before closing this window. If not, click Download again."
})
output$downloadData <- downloadHandler(
filename = "cleanedData.csv",
content = function(file) {
  write.csv(buttonClicked(),file,row.names = FALSE,na="")
}
)
  #REPORT GENERATOR
output$report <- downloadHandler(
filename = "report.html",
content = function(file) {
  # Copy the report file to a temporary directory before processing it, in
  # case we don't have write permissions to the current working dir (which
  # can happen when deployed).
  tempReport <- file.path(tempdir(), "report.Rmd")
  file.copy("report.Rmd", tempReport, overwrite = TRUE)
  # Set up parameters to pass to Rmd document
  params <- list(file = input$cleanedFile$datapath) 
  rmarkdown::render(tempReport, output_file = html_document,params = 
  params, envir = new.env(parent = globalenv())
   )
  }
 )
 })

“ output $ report”是我试图将输入CSV文件传递给RMD的部分

RMD文件的一部分:

 ---
 title: |
 | \vspace{5cm} 
 output:
 html_document:
  toc: yes
  toc_depth: 2
  toc_float: True
  number_sections: true
 params:
  file: NA
---
```{r, echo=FALSE,message=FALSE}
screData = read.csv(file = params$file, sep = ",")
```

错误是“找不到参数”

1 个答案:

答案 0 :(得分:0)

我应该传递一个字符,而不是在rmarkdown中传递NA。因此,在RMD文件中,我不得不更正以下部分:

参数:   文件:“”#代替NA