0
votes

I am writing a tutorial with learnr and want to include some "other forms of interactivity using Shiny" (from the learnr tutorial). I am new to Shiny but managed -- mainly with copy and paste -- to put to work several examples. Except the following one: (The code is taken from the second part of the video lecture "How to start with Shiny", code example "08-reactiveValues.R")

My YAML header:

output: 
    learnr::tutorial:
        progressive: true
        allow_skip: true
runtime: shiny_prerendere

My R chunks:

```{r my-dist-ui, context="render"}
actionButton(inputId = "norm", label = "Normal")
actionButton(inputId = "unif", label = "Uniform")
plotOutput("hist")

```

```{r my-dist-server, context="server"}

rv <- reactiveValues(data = rnorm(100))

observeEvent(input$norm, { rv$data <- rnorm(100) })
observeEvent(input$unif, { rv$data <- runif(100) })

output$hist <- renderPlot({ hist(rv$data) })
```

I can see an empty space reserved for the plot, but no plot. There is no change when I click at the buttons. There is no error message.

Could it be that some of the commands (e.g. reactiveValues or observeEvent) do not work with runtime: shiny_prerendered? (The above example works in its original form in the console. But another example with a plot – the Geyser example – does work in my Learnr Rmd-file.)

I am using R version 3.5.0 with RStudio Version 1.1.453 on a Intel Mac OS X 10_13_5, rmarkdwon 1.10, shiny 1.1.0 and learnr 0.9.2.

1
I think it is just a typo : you wrote content="server" instead of context="server". Once corrected, the plot is showing for me. - user9901566
No, this is not the problem. Sorry for the typo here. It happened after many trials, where I am sure, I used correctly "context = server". I updated my question. - petzi
I should also mention: Whenever I include the above two R chunks then all the other plots in my learnr file disappeared as well and the "Continue" button does not work anymore. (But the list of section chapter links on the left side do work.) - petzi
Just to be clear: I have fixed my typo, restarted R and cleared my rendered output and tried it again. The same problem as described in my question. - petzi
It works for me with the same code and YAML header so the reactive commands are not the source of the problem. Is that possible for you to send the entire file ? Maybe the problem comes from the interaction with other chunks. - user9901566

1 Answers

0
votes

I found my (dumb) error:

I used in in the same file for the other test plots the same plotOutput variable: plotOutput("hist").

When I changed it to plotOutput("hist2") and changed the server context accordingly to output$hist2 <- renderPlot({ hist(rv$data) }) all my plots appeared and the whole learnr file is working again.