-1

User uploads 3 data sets-> The app cleans them->User downloads cleaned data-> uploads the cleaned data to Report Generator->Reports is being generated (Html format). Cleaning part and downloading the cleaned data works fine. Everything is working above #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" is the part that I am trying to pass the input CSV file to RMD

Part of RMD file:

 ---
 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 = ",")
```

The error is "params is not found"

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
futurist
  • 1
  • 1
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Pictures of code are not helpful. When you say "none of them worked", what exactly was the problem? Did you get an error message of some sort or what happened exactly? – MrFlick Nov 26 '18 at 21:50
  • 1
    Please post code as text, and [not as images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557). – Anonymous coward Nov 26 '18 at 21:56
  • @MrFlick thanks for your feedback. This is the first time I am using stackoverflow. Please let me know if it is more clear now – futurist Nov 27 '18 at 02:03

1 Answers1

0

Instead of passing a NA in rmarkdown I should have passed a character. So in RMD file, I I had to correct the part below:

params: file: "" # instead of NA

futurist
  • 1
  • 1