flexdashboard
flexdashboard copied to clipboard
Nested child documents requires full path when using flexdashboard and runtime set to shiny.
Hi,
first of all thanks a lot for making flexdashboard it makes creating Shiny apps a breeze!
I have a project made of index.Rmd, child.Rmd and grandchild.Rmd (in the same directory).
index.Rmd contains:
---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
runtime: shiny
---
#Master
Row
------------------------
```{r child='child.Rmd'}
```
child.Rmd contains:
Row
-------------------------
Child.
```{r child='grandchild.Rmd'}
```
and grandchild.Rmd contains:
Row
-------------------------
Grandchild here.
When trying to compile index.Rmd (CTRL+SHIFT+K in RStudio Server) the compilation fails with error (in the Rmarkdown tab in RStudio):
Warning in readLines(if (is.character(input2)) { : cannot open file '/tmp/RtmphJxTx3/grandchild.Rmd': No such file or directory Quitting from lines 7-7 (/tmp/RtmphJxTx3/grandchild.Rmd) Quitting from lines 7-7 (/tmp/RtmphJxTx3/grandchild.Rmd) Warning: Error in readLines: cannot open the connection Stack trace (innermost first): 119: readLines 118: knit 117: FUN 116: lapply 115: process_tangle.block 114: process_tangle 113: withCallingHandlers 112: process_file 111: knit 110: FUN 109: lapply 108: process_tangle.block 107: process_tangle 106: withCallingHandlers 105: process_file 104: knit 103: knitr::purl 102: discover_rmd_resources 101: find_external_resources 100: copy_render_intermediates 99: output_format$intermediates_generator 98: <Anonymous> 97: do.call 96: contextFunc 95: .getReactiveEnvironment()$runWith 94: shiny::maskReactiveContext 93:
82: doc 81: shiny::renderUI 80: func 79: origRenderFunc 78: output$reactivedoc 3: <Anonymous> 2: do.call 1: rmarkdown::run
If you change child.Rmd to use the full path to grandchild.Rmd
Row
-------------------------
Child.
```{r child='/home/luca/sandbox/rmarkdown_grandchildren/grandchild.Rmd'}
```
then the dashboard is created without problems.
Initially I thought the problem was with knitr (I even reported a bug there that I closed https://github.com/yihui/knitr/issues/1434) but then I realized that the problem only arise when I use
flexdashboard and runtime: shiny (if you remove runtime: shiny from index.Rmd the dashboard compiles, but of course you can't use Shiny control anymore, which makes using flexdashboard quite pointless).
In normal Rmarkdown (to make html documents for example) you can nest grandchild.Rmd without having to specify the full path, which is why I think this behaviour in flexdashboard is a bug.
Cheers, Luca
P.s. this is the output of sessionInfo()
R version 3.3.3 (2017-03-06) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 9 (stretch)
locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=Cattached base packages: [1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached): [1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.5 tools_3.3.3 flexdashboard_0.5 yaml_2.1.13 Rcpp_0.12.12 stringi_1.1.5 rmarkdown_1.6 knitr_1.17
[12] jsonlite_1.5 stringr_1.2.0 digest_0.6.12 evaluate_0.9
I think this is an issue with child documents in runtime: shiny (i.e. they don't work). @jmcphers is that correct?
@jjallaire thanks for your reply! If you only include one child everything works (I have quite a few dashboards nesting children files only at one level and they work flawlessly even with runtime: shiny option). The problem only arises when nesting to more than one level, i.e. when you define a child in a child, like in the example I posted above. I am not sure if this is of help! @jjallaire @jmcphers if you think this is a Shiny issue I'll move the bug to their project.
I think it is of help. With runtime: shiny we do an analysis of the source code of the Rmd to determine it's dependencies. This isn't however recursive, so it would miss the child of the child. @jmcphers is that correct?
Yes, that's correct. The relevant code lives here:
https://github.com/rstudio/rmarkdown/blob/d31ec87679571a84092b5bec4f7de6f42511e9a4/R/html_resources.R#L326-L350
Thanks a lot @jjallaire and @jmcphers for looking into this! Do you want me to close the bug here and open it in the rmarkdown repo? I looked at the code but I am not sure I understand the logic well enough to come up with a solution, but will try as soon as I have some time.
One other tip for you that might actually get you the behavior you want to is to use runtime: shiny_prerendered. This is a different form of Shiny Rmd where the render step is a conventional knit. The code around Shiny output bindings is a bit more verbose but it may be worth it (these Rmds also load much, much faster because the HTML is already rendered). Docs on this are here: http://rmarkdown.rstudio.com/authoring_shiny_prerendered.html
Another example of this was reported in rmarkdown: https://github.com/rstudio/rmarkdown/issues/2419