I am trying to generate a pdf report of my carbon footprint calculator. I am retrieving reactive values, making them static and trying to put them in the simple report:
First part:
generate_pdf <- function() {
    output_file <- "my_shiny_app_output.pdf"
    render("C:/Users/timgr/OneDrive/Namizje/Tim/IZO/SustainableNGOs/R/RMD_file.Rmd", output_file = output_file)
    return(output_file)
  }
  
  # Event handler for the download button
  output$download_pdf <- downloadHandler(
    filename = function() {
      "my_shiny_app_output.pdf"
    },
    content = function(file) {
      pdf_file <- generate_pdf()
      file.rename(pdf_file, file)
    }
  )
Second part:
output$report <- downloadHandler(
    filename = function() {
      paste("report-", Sys.Date(), ".pdf", sep="")
    },
    content = function(file) {
      # Extract current values from your reactive functions
      totEm_food <- total_food_emissions()
      totEm_hotel <- total_hotel_stays_emissions()
      totEm_business <- total_business_travel_emissions()
      totEm_work <- total_office_work_emissions()
      totEm_commuting <- total_commuting_emissions()
      
      # Pass these values as params to the Rmd
      rmarkdown::render("RMD_file.Rmd", 
                        output_file = file,
                        params = list(
                          total_commuting = paste(totEm_commuting, "(kg CO2e)"),
                          total_work = paste(totEm_work, "(kg CO2e)"),
                          total_business = paste(totEm_business, "(kg CO2e)"),
                          total_hotel = paste(totEm_hotel, "(kg CO2e)"),
                          total_food = paste(totEm_food, "(kg CO2e)")
                        )
      )
    }
  )
RMD:
---
title: "Emission Report"
output: pdf_document
params:
  total_commuting: "NA"
  total_work: "NA"
  total_business: "NA"
  total_hotel: "NA"
  total_food: "NA"
---
## Emission Report
- Total Commuting Emissions: `r params$total_commuting`
- Total Work Emissions: `r params$total_work`
- Total Business Travel Emissions: `r params$total_business`
- Total Hotel Stay Emissions: `r params$total_hotel`
- Total Food Emissions: `r params$total_food`
I checked if reactive values work and they do, but PDF always generates NA result. What is wrong?
 
    