R Markdown script does not always display result

I have a problem with a RMD script. It runs. Once. After that, I get partial results.

The code:

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
  runtime: shiny
---
```{r global, include=FALSE}
library(dplyr)
library(flexdashboard)
Name=c('Test1', 'Test1', 'Test2')
Number = c(8, 9, 7)
zt <- data.frame(Name, Number)
PersonList <- sort(unique(zt$Name))

```
Selections {.sidebar}
===============================
```{r}
## The shiny part
selectInput("PersonSel", "Person: ", PersonList, selected = 'Test1')
```
Tab 1
======================================================================
Row {.tabset}
-----------------------------------------------------------------------
### Table
```{r}
renderTable({
cqi <- zt %>%
  na.omit() %>%
  filter(Name %in% input$PersonSel) %>%
  group_by(Number) %>%
  summarise(Count = n())
}, align='l')
```

But only this - it doesn't continue.

The only way to get it working again is to edit the script. Add a space or whatever.

Is seems very strange behavior. What can be the problem (and solution) here?

It would help if you enclose your entire example in four backticks (```` at the beginning and end) to make it more readable and copyable.

Thanks, is it usable now?

Yes, I see the same issue. Here is a smaller reprex. Running this once (in RStudio on macOS), the table draws and responds to the select input. Running it again without making any changes, the table doesn't draw. I don't know why.

---
title: "Dashboard"
output: 
  html_document:
    runtime: shiny
---
```{r}
zt <- data.frame(Name=c('Test1', 'Test1', 'Test2'), 
                 Number = c(8, 9, 7)
) 
PersonList <- sort(unique(zt$Name))


selectInput("PersonSel", "Person: ", PersonList, selected = 'Test1')

renderTable({
zt[zt$Name %in% input$PersonSel, ]
})
```

Same result here. I guess it goes wrong in the renderTable part. But why????

Reformatting the YAML as

---
title: "Dashboard"
output: html_document
runtime: shiny
---

should fix the issue.

2 Likes

Hi Mine,

Thanks, it doesn't work however. Do you have other suggestions?

Oh I see now what you mean, Mine. 'html_document' started on a new line, and that is the problem. The problem is solved now!

1 Like

Glad to hear it worked. Basically runtime is not an option for the output type, hence should not be listed under html_document but instead as its own entry in the YAML.