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 'RR_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 = "RR_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 'RR_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 'RR_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.
YY LIU is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Files in R/
are not available after installation. You should put any files you need in inst/
instead and access them with system.file("R_Month_Report.Rmd", package = "<your package>")
(inst
is the root).