rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.86k stars 968 forks source link

rmarkdown::run() with document in sub directories. #1977

Open PromyLOPh opened 3 years ago

PromyLOPh commented 3 years ago

I’m running a Rmarkdown server (v0.5.0) using

R -q --no-save -e 'rmarkdown::run(file = NULL, dir = ".", shiny_args=list(port=8080, quiet=FALSE, launch.browser=FALSE))'

from the command line, trying to serve the gh-pages branch of this very repository. dir is intentionally set to the current directory, which contains the source checkout. Now, this directory contains multiple subdirectories with different Rmd files, but only the ones in the top directory (i.e. .) are actually accessible. The problem is that the Shiny server returns HTML with relative references. For files in the root directory (for example /index.Rmd) this is fine, but for other files (for example /demos/1-example.Rmd) is is not. Specifically resources searched for in the directories shared/ and rmd_resources/ seem to prevent proper loading of documents.

I would expect Rmarkdown files in the entire subtree to be accessible with the above command, disregarding their location.

Session info:

> xfun::session_info()
R version 4.0.3 (2020-10-10)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Locale:
  LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C
  LC_TIME=de_DE.UTF-8        LC_COLLATE=de_DE.UTF-8
  LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=de_DE.UTF-8
  LC_PAPER=de_DE.UTF-8       LC_NAME=C
  LC_ADDRESS=C               LC_TELEPHONE=C
  LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

Package version:
  compiler_4.0.3  graphics_4.0.3  grDevices_4.0.3 stats_4.0.3
  tools_4.0.3     utils_4.0.3     xfun_0.19
>
>

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

cderv commented 3 years ago

Hi,

It is not clear to me what you are trying to do. Can you be more precise ?

here are some information to help:

rmarkdown::run is dedicated to render document using a shiny runtime. You can use if on a Rmd file having a shiny runtime, shiny Rmd or learnr tutorials for example. It is not made for serving a whole website. See https://bookdown.org/yihui/rmarkdown/shiny-start.html

"To run a Shiny document in RStudio, you need to click the button “Run Document” on the editor toolbar (RStudio will automatically replace the “Knit” button with “Run Document” when it detects a Shiny document). If you do not use RStudio, or want to run the document in the R console for troubleshooting, you can call the function rmarkdown::run() and pass the filename to it."

Are you trying to use it on shiny Rmd documents ?

trying to serve the gh-pages branch of this very repository.

You mentioned this repo gh-page branch - it contains what I believe to be a Rmarkdown website You can't just call rmarkdown::run on this folder. For website, there is rmarkdown::render_site() See more about website here: https://bookdown.org/yihui/rmarkdown/rmarkdown-site.html

Also, a reminder that for questions, you can also ask on https://rstudio.community.com. It is better suited for generic question.

I am waiting for more details on your issue if there is still one, otherwise I'll close this as a question topic.

PromyLOPh commented 3 years ago

My quest is to serve all Rmd files from a subtree (i.e. directory and all subdirectories). These can be anything, from “simple” Rmarkdown files to shiny documents (using learnR). The gh-pages branch is just a simple example of how run() fails to work with subdirectories. There is usually no site configuration _site.yaml, because it’s not a website, just a bunch of unrelated documents. render_site() won’t work with interactive learnR tutorials, because it generates a static website, right?

It is not made for serving a whole website.

But the documentation clearly states “The server will render any R Markdown (.Rmd) document in dir”. I’m confused why that would not include subdirectories and would consider it a bug, because it fails to do so in very non-obvious ways (i.e. showing a blank page with no explanation whatsoever).

(I’m using rmarkdown v2.5 – sorry about the mixup.)

cderv commented 2 years ago

Sorry for the delay on this. We're going back on rmarkdown an I am looking at still opened issues.

These can be anything, from “simple” Rmarkdown files to shiny documents (using learnR).

I think your issue relates to this other one: https://github.com/rstudio/rmarkdown/issues/2037 Currently rmarkdown::run won't be able to work with multiple shiny_prerendered documents. learnr are shiny prerendered document. This is probably due to a limitation in the current design that would need to change: https://github.com/rstudio/rmarkdown/issues/1576

The server will render any R Markdown (.Rmd) document in dir

This will apply in case of other documents or shiny document inside the directory. rmarkdown::run() is still design to run shiny apps. It will call shiny::runApp() to launch a local shiny server. There is no R Markdown server. However, if you have several documents in your directory, and that you are running a document with runtime: shiny (often index.Rmd), you'll be able to route toward another document. This is useful for links between documents for example. This should work for runtime: shiny document only because the issue linked above for other.

I’m confused why that would not include subdirectories and would consider it a bug

Considering all of the above limitation, it seems indeed that this is not working with subdirectories. The page is blank because some resources are not found.

Here is a repo example: https://github.com/cderv/test-shiny-rmd

Doing

rmarkdown::run("index.Rmd")

will correctly launch the app.

The about page can be rendered (following the link) but the page in sub directories have errors loading. JS resources are looked for in the sub directory when they are in the root dir. image

So yes it seems sub directories are not supported. I don't know how popular this usage of running a shiny apps with several Rmd shiny document is.

For non Rmd shiny document, one would use rmarkdown::render_site() or another website tools like distill or block**

It is either a path issue or specific to rmarkdown::run() behavior.