Error in shiny prerendered runtime when introducing a selectInput() - r

I have a functioning Shiny interactive document (.Rmd) file that works fine locally and on shinyapps.io. I am trying to prerender it using instructions here (http://rmarkdown.rstudio.com/authoring_shiny_prerendered.html) but am running into an unusual error when I introduce a selectInput().
The error message I am getting is the following:
Here's a mininal code block that produces the error.
(app.Rmd)
---
title: 'a title'
output: html_document
runtime: shiny_prerendered
---
```{r, context = 'setup', include=FALSE}
library(shiny)
```
```{r, context='render'}
selectInput('hello','Hi',choices=c('1','2'))
```
```{r, context='server'}
```
Here is my sessionInfo():
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.0.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.6 digest_0.6.10 rprojroot_1.1 mime_0.5 R6_2.1.2 xtable_1.8-2 backports_1.0.3
[8] magrittr_1.5 evaluate_0.10 stringi_1.1.1 rmarkdown_1.3 tools_3.2.2 stringr_1.1.0 httpuv_1.3.3
[15] yaml_2.1.13 htmltools_0.3.5 knitr_1.15.1
I've tried changing the encoding of my Rmd to UTF-8 with no luck. Changing the runtime to "shiny" (from "shiny_prerendered") seems to fix the problem. Is this a bug in the "shiny_prerendered" runtime or am I doing something wrong?

Related

Quarto Not Rendering

My quarto documents have stopped rendering suddenly. I have reinstalled RStudio and the quarto package, but this issue persists.
When I open a new quarto document, I no longer see the boilerplate material in the new document. The document is empty as if I had selected Create Empty Document, but I haven't.
Then, the document renders when all I include is raw text, but when I include an r code chunk, I get the following message.
Error in xfun::normalize_path(path, ..., must_work = must_work, resolve_symlink = FALSE) :
unused argument (resolve_symlink = FALSE)
Calls: .main ... execute -> setwd -> dirname -> <Anonymous> -> normalize_path
Execution halted
Here is the quarto document I'm attempting to render.
---
title: "Testing"
---
```{r}
mtcars |> print()
```
Here is my session info:
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.utf8
[2] LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 ps_1.7.2 digest_0.6.30 later_1.3.0
[5] jsonlite_1.8.4 pacman_0.5.1 evaluate_0.20 zip_2.2.2
[9] rlang_1.0.6 cli_3.4.1 rstudioapi_0.14 fs_1.5.2
[13] rmarkdown_2.20 tools_4.2.2 yaml_2.3.6 xfun_0.35
[17] fastmap_1.1.0 parallel_4.2.2 compiler_4.2.2 processx_3.8.0
[21] htmltools_0.5.4 knitr_1.41 quarto_1.2
I was having the exact same issue with knitr, this worked for me:
Remove the package "xfun" from the packages section, then reinstall it immediately after.
I'd tried changing the root install for R and everything. Turns out it was just xfun being weird.
Found the solution on the Posit Community forum.
Do you have any spaces in the filename or file path? That was preventing me from rendering for a bit.

R Markdown: knitr option results='hide' not working

I'm trying to produce a chunk code that executes and shows the code but hides the output. I know that the way to do it is by adding echo = T, results = 'hide' in knitr chunk options, as suggested here. However, in my case, this still produces the output, any ideas why?
My session info:
> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.3 backports_1.1.2 rprojroot_1.3-2 htmltools_0.3.6
[5] tools_3.4.3 yaml_2.2.0 Rcpp_0.12.19 rmarkdown_1.10
[9] knitr_1.20 digest_0.6.18 evaluate_0.12
Plots can be suppressed with the option fig.keep = 'none'.

Can't get bookdown rmd_subdir ["dir"] to work

I tried to use the new rmd_subdir option in the _bookdown.yml by setting a list of subdirectories. I copied all files except the index.Rmd of a freshly created bookdown project in a folder called content. The following setting in the _bookdown.yml does work
rmd_subdir: = yes
However when I change the _bookdown.yml to the following only the index.Rmd is compiled.
_bookdown.yml
book_filename: "_tmp_rmd_subdir"
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
rmd_subdir: ["content"]
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_0.12.15 bookdown_0.7 digest_0.6.14 rprojroot_1.3-2 backports_1.1.2
[6] magrittr_1.5 evaluate_0.10.1 stringi_1.1.6 rstudioapi_0.7 rmarkdown_1.9
[11] tools_3.4.3 stringr_1.3.0 tinytex_0.4 xfun_0.1 yaml_2.1.19
[16] rsconnect_0.8.5 compiler_3.4.3 htmltools_0.3.6 knitr_1.20
This should be fixed in the development version of bookdown. Please try
devtools::install_github('rstudio/bookdown')

R looks in the wrong place for html dependency

I am trying to knit a flexdashboard to an html file. My flexdashboard includes leaflet maps. The knit.md file compiles correctly. At the last stage, converting the knit.md to an html file, I get an error. Apparently leaflet is looking for html dependencies in the R 3.3.2 folder, rather than the R 3.4.2 folder. I originally built this flexdashboard months ago on a different machine on which I had R 3.3.2 (although I was using 3.4.1 I believe to build this). So the problem appears to be that leaflet still looks in the old R-3.3.2 folder for its dependencies even though I've updated and reinstalled leaflet multiple times, trying to fix this problem.
Does anyone know how to tell leaflet to look in the correct place for its html dependencies?
output file: myflexdashboard.knit.md
Error: path for html_dependency not found: C:/R/R-3.3.2/library/leaflet/htmlwidgets/lib/leaflet-providers
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.2 backports_1.1.1 magrittr_1.5 rprojroot_1.2 htmltools_0.3.6
[6] tools_3.4.2 flexdashboard_0.5.1 yaml_2.1.15 Rcpp_0.12.14 stringi_1.1.6
[11] rmarkdown_1.8 knitr_1.17 jsonlite_1.5 stringr_1.2.0 digest_0.6.12
[16] packrat_0.4.8-1 evaluate_0.10.1

accessing global environment objects created in cached chunks Rmarkdown documents

I want to run a R script to run a simulation and cache the results for the Rmarkdown document. I am using Rstudio and try to create an HTML report by using knit HTML Here's a simple example.
```{r test_global_env,cache=TRUE}
print(getwd())
source("./test_script.R")
```
```{r test_global_env_2}
print(a)
```
and test_script.R is as follows
a<-1
When I change the cache option for the chunk to FALSE, print(a) works. If I set it to TRUE, it works the first time, the second time, I get object 'a' not found error.
A similar question is Can knit2pdf use the global environment? , but I could not figure out if it applies to my situation. Here is the sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
other attached packages:
[1] knitr_1.2 igraph_0.6.5-2 lubridate_1.3.0
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.3 formatR_0.8
[4] memoise_0.1 plyr_1.8 stringr_0.6.2
[7] tools_3.0.0

Resources