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

shiny_prerendered parses DESCRIPTION file from wrong location #2540

Open
5 tasks done
nanxstats opened this issue Feb 2, 2024 · 5 comments
Open
5 tasks done

shiny_prerendered parses DESCRIPTION file from wrong location #2540

nanxstats opened this issue Feb 2, 2024 · 5 comments
Assignees

Comments

@nanxstats
Copy link

Under specific conditions, rmarkdown/learnr incorrectly searches for and attempts to parse a DESCRIPTION file outside the intended project directory. This issue arises if the DESCRIPTION file contains errors such as formatting issues, causing the quiz component to remain in a "loading" state. This state persists without providing an error message to identify the issue for developers or users.

In Posit Workbench, this problem becomes a HTTP 500 error in the Chrome DevTools Network tab, with a possible DCF parsing error message in the response.

Minimal reproducible example

usethis::create_project("example")

In the new project window, run

usethis::use_description()
writeLines(append(readLines("DESCRIPTION"), "", after = 1), "DESCRIPTION")
fs::file_move("DESCRIPTION", "~/DESCRIPTION")
rmarkdown::draft("example.Rmd", template = "tutorial", package = "learnr", create_dir = FALSE, edit = FALSE)

Open example.Rmd, run the document, and navigate to "Topic 2". The quiz will display "Loading..." instead of the content.

Session info

> xfun::session_info('rmarkdown')
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.2.1, RStudio 2023.12.1.402

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3   bslib_0.6.1       cachem_1.0.8     
  cli_3.6.2         digest_0.6.34     ellipsis_0.3.2   
  evaluate_0.23     fastmap_1.1.1     fontawesome_0.5.2
  fs_1.6.3          glue_1.7.0        graphics_4.3.2   
  grDevices_4.3.2   highr_0.10        htmltools_0.5.7  
  jquerylib_0.1.4   jsonlite_1.8.8    knitr_1.45       
  lifecycle_1.0.4   magrittr_2.0.3    memoise_2.0.1    
  methods_4.3.2     mime_0.12         R6_2.5.1         
  rappdirs_0.3.3    rlang_1.1.3       rmarkdown_2.25   
  sass_0.4.8        stats_4.3.2       stringi_1.8.3    
  stringr_1.5.1     tinytex_0.49      tools_4.3.2      
  utils_4.3.2       vctrs_0.6.5       xfun_0.41        
  yaml_2.3.8       

Pandoc version: 3.1.11.1

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('rmarkdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown")?

@gadenbuie
Copy link
Member

Thanks for the report @nanxstats! This seems specific to learnr, or have you seen this behavior with other rmarkdown formats? If not, I'll move this over to the learnr bug tracker.

@nanxstats
Copy link
Author

@gadenbuie Sure thing. I think this issue is more prevalent for learnr projects because it's probably a major source of usage of the shiny_prerendered runtime, although the fix could come from different places.

@gadenbuie
Copy link
Member

@nanxstats Can you try this with another shiny prerendered document that isn't a learnr tutorial? Does it also create problematic behavior under similar circumstances (where an unrelated DESCRIPTION file exists in a parent directory)?

@nanxstats
Copy link
Author

@gadenbuie Good idea. I further tried the two examples in Prerendered Shiny Documents with html_document and flex_dashboard outputs - the Shiny components in both of them work ok even with the unrelated DESCRIPTION file in the parent directory. This might suggest the issue is more learnr-specific.

Also, here is a slightly updated minimal reproducible example - it gives a better hint on where the error happened (a read.dcf() call somewhere):

usethis::create_project("example")
# In the new project
usethis::use_description()
writeLines(append(readLines("DESCRIPTION"), "Imports", after = 1), "DESCRIPTION")
fs::file_move("DESCRIPTION", "~/DESCRIPTION")
rmarkdown::draft("example.Rmd", template = "tutorial", package = "learnr", create_dir = FALSE, edit = FALSE)

Run document:

Loading required package: shiny

Listening on http://127.0.0.1:3852
Warning: Error in read.dcf: Invalid DCF format.
Regular lines must have a tag.
Offending lines start with:
  Imports
  3: <Anonymous>
  1: rmarkdown::run

@cderv
Copy link
Collaborator

cderv commented Feb 5, 2024

@gadenbuie do you want to move this issue then as it seems learnr related ?

Though we do read dcf in this code base when handling dependencies

dependencies <- lapply(shiny_prerendered_dependencies$deps, function(dependency) {
# no transformation in dev mode (so browser dev tools can map directly
# to the locations of CSS and JS files in their pkg src directory)
if (nzchar(Sys.getenv("RMARKDOWN_SHINY_PRERENDERED_DEVMODE")))
return(dependency)
# see if we can convert absolute paths into package-aliased ones
if (is.null(dependency$package) && is.character(dependency$src$file)) {
# check for a package directory parent
package_dir <- proj_root(dependency$src$file)
# if we have one then populate the package field and make the
# src$file relative to the package
if (!is.null(package_dir)) {
package_desc <- read.dcf(file.path(package_dir, "DESCRIPTION"),
all = TRUE)
dependency$package <- package_desc$Package
# named to something that doesn't start with 'package' to deter lazy name matching
dependency$pkgVersion <- package_desc$Version
dependency$src$file <- normalized_relative_to(package_dir,
dependency$src$file)
}
}

We do try to find project root but related to a dependency file. Is there also a read dcf call in learnr ? Or would this be this one ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants