golem icon indicating copy to clipboard operation
golem copied to clipboard

[BUG] consulting about using the golem package to develop a Shiny application (embedding Rmarkdown) and packaging it into a package, but encountering issues with calling Rmarkdown files.

Open IL04 opened this issue 1 year ago • 2 comments

Describe the bug I am currently researching the development of a Shiny application (embedding Rmarkdown files) using the golem package. I have encountered a problem where after developing the Shiny application with the golem package and packaging it using devtools, upon reinstalling the package, I am unable to call my embedded Rmarkdown file. The error message "Error: The file 'R\R_Month_Report.Rmd' does not exist." is displayed. I would like to inquire how to resolve this issue. I have been unable to find a solution.

To Reproduce The code for calling the Rmarkdown file in Shiny server is as follows:

output$rendered_markdown <- renderText({
  rmarkdown::render(input = "R\\R_Month_Report.Rmd", 
                    output_file = paste0(path_excel_all, "\\R_Month_Report", Sys.Date(), ".html"))
})

My Rmarkdown file is located in the R folder of the RProj. In the Rproj environment, everything works fine when opening the Shiny app using run_app().

Then, after packaging with devtools using the code:

devtools::build(path = "E:\\myShinyApp\\autoreport")

The package name is set as autoreport. After installing and loading the autoreport package, when I reopen an R file in a non-Rproj environment and run autoreport::run_app(), the Shiny interface opens successfully. However, there is an unexpected issue where the functionality of the rmarkdown::render call is not working as expected, and it shows an error: "Error: The file 'R\R_Month_Report.Rmd' does not exist."

Upon checking the compiled R package, I found only three files in the R folder, two of which are rdb and rdx files.

Subsequently, I tried adding the following code in the 02_dev.R file with the explanation "Add internal datasets If you have data in your package":


usethis::use_data_raw(name = "R\\R_Month_Report.Rmd", open = FALSE)
usethis::use_data_raw(name = "R\\R_Month_report_word.Rmd", open = FALSE)
usethis::use_data_raw(name = "R\\template_word.docx", open = FALSE)

However, none of these attempts were successful, and the error "Error: The file 'R\R_Month_Report.Rmd' does not exist." persists.

I have been trying to find a solution for two days without success. I would like to seek advice from yours on how to resolve this issue in this scenario.

IL04 avatar Sep 15 '24 07:09 IL04