Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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. #1181

Closed
IL04 opened this issue Sep 15, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@IL04
Copy link

IL04 commented Sep 15, 2024

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 IL04 added the bug Something isn't working label Sep 15, 2024
@VincentGuyader
Copy link
Member

HI,

you have to put your Rmd file in the inst/ folder of your package (not un the R/ folder)
then you will be abler to access it with system.file("R_Month_Report.Rmd",package = "yourgolem")
or app_sys("R_Month_Report.Rmd")

Even if you place the file to be compiled in the correct location, the approach with renderText doesn't seem appropriate to me. Instead, you should use the following

output$rendered_markdown  <- renderUI({
  includeMarkdown(app_sys("rendered_markdown "))
})

@IL04
Copy link
Author

IL04 commented Sep 16, 2024

HI,

you have to put your Rmd file in the inst/ folder of your package (not un the R/ folder) then you will be abler to access it with system.file("R_Month_Report.Rmd",package = "yourgolem") or app_sys("R_Month_Report.Rmd")

Even if you place the file to be compiled in the correct location, the approach with renderText doesn't seem appropriate to me. Instead, you should use the following

output$rendered_markdown  <- renderUI({
  includeMarkdown(app_sys("rendered_markdown "))
})

HI,

you have to put your Rmd file in the inst/ folder of your package (not un the R/ folder) then you will be abler to access it with system.file("R_Month_Report.Rmd",package = "yourgolem") or app_sys("R_Month_Report.Rmd")

Even if you place the file to be compiled in the correct location, the approach with renderText doesn't seem appropriate to me. Instead, you should use the following

output$rendered_markdown  <- renderUI({
  includeMarkdown(app_sys("rendered_markdown "))
})

HI, VincentGuyader,

Thank you for your great suggestion! The problem has been solved with your good ideas, and it now works well.

Thanks a lot.

The Shiny app works correctly, similar to the type of exe, using the method electron-quick-start.

Best wishes,
Yuyang

@VincentGuyader
Copy link
Member

If needed for someone else, here are a fully functional example : https://github.com/ALanguillaume/pkg.shiny.report/

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants