The documentation of the new learnr-package states that
it’s also possible to add other forms of interactivity using Shiny (e.g. for teaching a statistical concept interactively).
I tried it with the provided example but I could not manage it. The slider does appear but not the plot. I used:
---
title: "Tutorial"
output:
learnr::tutorial:
progressive: true
allow_skip: true
runtime: shiny_prerendered
tutorial:
version: 0.1
---
```{r setup, include=FALSE}
library(learnr)
library(checkr)
library(shiny)
knitr::opts_chunk$set(exercise.checker = checkr::checkr_tutor)
```
The example did work with
---
title: "R Notebook"
output: html_notebook
runtime: shiny
---
I tracked the problem down: It was completely my own fault. I used the same name for the input variable in another R chunk with shiny code.
I did not get any error message, the output just did not show up.
Related
I use updated quarto and Rmarkdown and vtree ‘5.4.6’:
In the same project and same session:
Rmarkdown does what quarto does not:
Rmarkdown renders vtree(iris, "Species") and quarto not (allthough quarto renders inline)
What could be the problem for this?
See here a reproducible example:
1. Rmarkdown
---
title: "test"
author: "Me"
date: '2022-06-18'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(vtree)
```
## R Markdown
```{r cars}
vtree(iris, "Species")
```
2. Quarto
---
title: "Untitled"
format: html
editor: visual
---
## Quarto
```{r}
library(vtree)
vtree(iris, "Species")
```
When I click the Render button: -> it is NOT renderred:
When I render inline: -> it is renderred:
Quarto works a bit differently than R Markdown as it will run R only for the knitting process, and not for the conversion to output format, here HTML.
From the error message, vtree is writing to file the output in the R session temp folder. This folder is not persistent after the R session is closed, which happens once Quarto have run all the computation output. This means that the png file does not exists anymore when converting to HTML, hence the no image shown in HTML.
(regarding knitr warning, I believe it is knitr version matter, but that does not change the output).
Looking at vtree::vtree() function, it seems when knitting to HTML is detected R temp folder is used if none provided. IMO this should ne behave that way and it is an issue in vtree package.
To overcome the issue, you need to not let vtree do the default provide yourself a path. You can do that with folder argument. So this should work
---
title: "Untitled"
format: html
keep-md: true
---
## Quarto
```{r}
library(vtree)
if (!dir.exists("vtree_save")) dir.create("vtree_save")
vtree(iris, "Species", folder = "vtree_save")
```
I would report an issue in vtree repo about this behavior.
I am the author of the vtree package. I have just made a change to the code which I believe fixes the problem. See https://github.com/nbarrowman/vtree where there are instructions for downloading version 5.5.8 of the vtree package, which includes the fix.
I'm unable to load images for my RMarkdown when I use runtime:shiny
Here is a small example, without "runtime:shiny" it's working fine, but if I uncomment this line, it doesn't work:
---
title: "Untitled"
output:
html_document:
#runtime: shiny
---
```{r }
knitr::include_graphics("D:/Maths/pic.png")```
I am trying to make some R tutorial presentation using "tutorial" package. There is a link "powered by datacamp" after each code window. I think it is far too much. Is there any way to remove some of "powered by datacamp"? and make it show at the beginning or end of the tutorial?
For example, when you create a R markdown file with tutorial::go_interactive(), it gives "powered by datacamp" after each code window:
---
title_meta: 'R tutorial'
title: Vectors
description: ''
---
```{r, include=FALSE}
tutorial::go_interactive()
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
# no pec
I'm struggling with what to Google to start solving this one. It might be a Windows question and not an R question but I could do with some help.
I am using rmarkdown::render to generate html reports. I have a master.Rmd which calls some child_docs. I use the argument output_file = to name the html document. This works fine and I can successfully generate documents called my_report1.html. When I open the html document in my browser (both Chrome and FireFox) the browser tab is labelled as master.utf8.md:
In the past the tab label used to be my_report1.html. I want to fix this because I regularly have multiple reports open and navigating between the tabs to find which report I want is now painful.
Any thoughts on what to check?
The YAML:
---
output:
html_document:
toc: true
toc_float: true
params:
lot: 1
editor_options:
chunk_output_type: console
---
Chunk setup:
```{r setup, include=FALSE}
## GLobal chunk options
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
Update: I think this is to do with the YAML title:. I'm going to open a new question with a better example.
I managed to cobble together a work around for this. The tab name in a browser comes from the title declared in the YAML even if you supply a file name to output_file in rmarkdown::render. I wanted to set my title dynamically and this can be done with using the methods described here, example:
---
output: html_document
---
```{r}
title_var <- "Sample Title"
```
---
title: `r title_var`
---
However, I needed an extra work around to suppress the title because I didn't actually want it to make a title. This can be done by using the following css (top of doc or separate file):
<style>
.title{
display: none;
}
</style>
I've noticed that when I have an Rmd with runtime: shiny in the YAML, code chunks don't seem to be read from cache. I'm wondering if using the shiny engine for rmarkdown just doesn't support chunk caching, or am I doing something wrong?
Example Rmd file:
---
title: "Cache test"
output: html_document
---
```{r cache=TRUE}
Sys.sleep(10)
```
If you run this 5 times, only the first time will take 10 seconds, and any subsequent run will be fast.
But if you add the runtime: shiny option to the YAML, then every single run will take 10 seconds.
(PS question: any better way to test whether or not code chunks cache is being used?)
i ran into the same problem where, in runtime: shiny, the cache switch was ignored.
Nowadays there is a workaround, using runtime: shiny_prerendered and context="data" with cache=TRUE:
---
title: "Cache test"
output: html_document
runtime: shiny_prerendered
---
```{r,context="data", cache=TRUE}
Sys.sleep(10)
```
this behaves as expected; on the first run, rendering takes 10 seconds; on all subsequent runs, the cached chunk is used.