Open heimschf opened 3 years ago
Attaching @cderv and @gadenbuie as this might be a rmarkdown/learnr issue
@cpsievert, @cderv, @gadenbuie many thanks for digging into this. Hope you find a solution, Thanks.
Typically that error indicates that the learnr document needs be re-rendered. The best way to confirm that you've completely re-rendered the document is to click on Clear Prerendered Output in the drop down menu of the Run Document button. Then click run document again to prerender and run the app.
Thanks for your comment, @gadenbuie , I have tried the proposed procedure using both clear prerendered output and clear knitr cache. But this did not help. Also, I tried to move the .Rmd file in a new folder and renamed it and have re-run again. But the error message from "couldn't normalize path in addresourcepath..." persists, unfortunately.
Okay, well that rules out the easy answer. I wonder if the issue you're seeing is specific to shinydashboard? I'll try to investigate further this week.
thanks, @gadenbuie , it seems that it is specific to shinydashboard but the error only arises together in use with rmarkdown package, which is imported using the learn package. Using a "single shinydashboard" in a app.R file works without problems.
The other thing you could try is to see if shiny dashboard components work as expected in the runtime: shiny_prerendered
context, without learnr. For example in a document with the following YAML frontmatter
---
title: "Minimal Example"
output: html_document
runtime: shiny_prerendered
---
Thanks for the idea, but same result... (same error message)
That's a good data point! Does it also fail (in a regular html_document
) if you remove the library(learnr)
call?
sorry I should have mentioned, yes, in addition have also checked this, but still fails...
No worries! That reduces the scope of the problem a bit and indicates that learnr isn't specifically involved. Most likely this is an issue with shinydashboard when used in a shiny prerendered document.
@cpsievert @cderv This is really a problem with shiny prerendered rmarkdown
documents. Here's a minimal reprex:
---
title: "Minimal Example"
output: html_document
runtime: shiny_prerendered
---
```{r setup, include = FALSE}
library(shinydashboard)
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(),
title = "Dashboard example"
)
I tracked down the problem to [these lines in `rmarkdown:::shiny_prerendered_html()`](https://github.com/rstudio/rmarkdown/blob/bab481aa016f38a94d08f4c03284e9273804b3d4/R/shiny_prerendered.R#L145-L154). The shinydashboard dependency is included in the prerendered doc
```r
# before L145-L154
str(dependencies[[10]])
List of 11
$ name : chr "shinydashboard"
$ version : chr "0.7.1"
$ src :List of 1
..$ file: chr "/Library/Frameworks/R.framework/Versions/3.6/Resources/library/shinydashboard"
$ meta : NULL
$ script : chr "shinydashboard.min.js"
$ stylesheet: chr "shinydashboard.css"
$ head : NULL
$ attachment: NULL
$ package : chr "shinydashboard"
$ all_files : logi TRUE
$ pkgVersion: chr "0.7.1"
- attr(*, "class")= chr "html_dependency"
but the $src$file
is replaced with ""
, which obviously leads to errors.
# after L145-154
str(dependencies[[10]])
List of 10
$ name : chr "shinydashboard"
$ version : chr "0.7.1"
$ src :List of 1
..$ file: chr ""
$ meta : NULL
$ script : chr "shinydashboard.min.js"
$ stylesheet: chr "shinydashboard.css"
$ head : NULL
$ attachment: NULL
$ all_files : logi TRUE
$ pkgVersion: chr "0.7.1"
- attr(*, "class")= chr "html_dependency"
The primary cause is a conflation of two things:
$package
is not NULL
in the dependency stored in the prerendered document (before example above)system.file()
rather than the package=
argument of htmlDependency()
when declaring its dependenciesResolving either one could resolve this particular issue. But we may not need to replicate htmltools' package dependency resolution step in rmarkdown since it was added to rmarkdown 5 years ago when the package=
argument was just being introduced.
Thanks @gadenbuie !
Based on all this investigation, I'll have a closer look on the rmarkdown side regarding this mechanism. Thanks for looking into this !
Ok I understand now better.
I think this is also a edge case because shinydasboard resources are at the root of the package. When inserting the dependencies into the prerendered HTML, rmarkdown will process the dependencies and add the package field + normalize the src$file
relative to the package dir root.
THis happens here: https://github.com/rstudio/rmarkdown/blob/bab481aa016f38a94d08f4c03284e9273804b3d4/R/shiny_prerendered.R#L309-L325
However, as the root installed package is used as src$file
in shinydashboard, the normalize relative to doesn't work as expected. At least I think so
# what happens
rmarkdown:::normalized_relative_to(system.file(package = "shinydashboard"), system.file(package = "shinydashboard"))
#> [1] "C:/Users/chris/Documents/R/win-library/4.1/shinydashboard"
# this does work
rmarkdown:::normalized_relative_to("a/b", "a/b/c")
#> [1] "c"
# not work as expected
rmarkdown:::normalized_relative_to("a/b", "a/b")
#> [1] "C:/Users/chris/AppData/Local/Temp/Rtmpqev1CI/reprex-df473ab7310-waspy-bunny/a/b"
# what should happen
xfun::relative_path(xfun::normalize_path("a/b"), dir = xfun::normalize_path("a/b"))
#> [1] "."
So we may be able to fix this, by fixing the relative path function. I'll try it.
However, I understand that:
package=
when missing, and changing src$file
to relative pathpackage=
and recreating the src$file
as a absolute path including package path.
I am not sure yet to understand why this double process. package=
. This could also changeDo you think we should change one of the above ?
So we may be able to fix this, by fixing the relative path function. I'll try it.
As expected, it fixes the above issue. This lives currently in rstudio/rmarkdown@fix/relative-same-dir and can be tested with
pak::pak("rstudio/rmarkdown@fix/relative-same-dir")
Not sure this is the right fix for this. The HTML deps processing still puzzles me (but it is there since years ago for a reason I am sure)
However, it shows once again than file path handling is critical. I'd really like to consider fs for this as maybe it could be more robuste on the long term.
Thanks for the follow up @cderv. I think it's likely that we no longer need the shiny prerendered process to be so hands-on with the html dependencies, but it'd be good to talk through that a bit more. Should we move this issue into rmarkdown?
Should we move this issue into rmarkdown?
Yes we could. I don't have right to do that. @cpsievert ?
I think it's likely that we no longer need the shiny prerendered process to be so hands-on with the html dependencies, but it'd be good to talk through that a bit more
I agree. I think shinydashboard could also use the package
argument in htmlDependency
now.
Seems I don't have permission to transfer either
I deployed a shiny app that is generated with the package learn, shinydashboard and shiny. Prior to updating rmarkdown to the latest version (before I used version 1.12) everything worked fine.
I obtain the following error when deploying my shiny-app (both locally and in Browser):
Below you find my
sessionInfo()
:You find a minimal working example below, please advise on this issue.
APP zu deskriptiven Statistiken