0

I have a very simple flexdashboard where I would like display the iris data in a table using DT::renderDT(iris). It renders when I click "knit" in RStudio, but when I run markdown::render("test.Rmd") I get junk. It won't render on shinyapps.io either. Is there something trivially simple that I'm missing?

---
title: "Iris data"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    runtime: shiny_prerendered
---

```{r setup, include=FALSE}
rm(list = ls())
library(flexdashboard)

```


Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
DT::renderDT(iris)
``

Produces the following:

enter image description here

HCAI
  • 2,213
  • 8
  • 33
  • 65

1 Answers1

1

Yes, there is ^^

It took me quite some time to find the mistake, but you are missing one of the three backticks in the definition of your chunk.

This should work:

---
title: "Iris data"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    runtime: shiny_prerendered
---

```{r setup, include=FALSE}
rm(list = ls())
library(flexdashboard)

```


Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
data <- shiny::reactive({iris})
DT::renderDT(data())
```
Max Teflon
  • 1,760
  • 10
  • 16
  • Thank you for looking at this so carefully! Unfortunately, it was a copying mistake from my side. Does it create a html when you do: rmarkdown::render("test.Rmd")? – HCAI Mar 12 '21 at 13:41
  • yes, it does. Did you set your markdown to use shiny for the pre-rendering? I was asked this question some time ago and just set it to auto use it... – Max Teflon Mar 12 '21 at 13:47
  • It does only work if a shiny-instance is running though. – Max Teflon Mar 12 '21 at 13:49
  • One last thought - did you try using `DT::datatable()` instead of `renderDT`? – Max Teflon Mar 12 '21 at 13:50
  • Ohhh that works!!! DT::datatable() looks quite nice too. Thank you very much for your suggestions. The table appears, now I can't see any plots. Do you think this is a version issue? – HCAI Mar 12 '21 at 14:40
  • I think it is a shiny issue. The render function render is so that a non-static environment can display it. The simple datatable function creates a static js-object that can be displayed in a static html-file. – Max Teflon Mar 12 '21 at 14:42
  • ahhh I see, thank you. Theoretically it's not a reactive thing that I'm looking at. Just presenting data and plotting it with ggplot. It knits and works in RStudio when I click knock. I now can upload to shinyapps but only the tables appear. Do you think this is something other people have come across? – HCAI Mar 12 '21 at 14:50
  • 1
    On shiny-Apps you might need to make your plots reactive again by using the appropriate shiny-functions (shiny::renderPlot and such) but I did only build stand-alone shiny apps and no fley-dashboards until now, so I could be wrong... – Max Teflon Mar 12 '21 at 14:56
  • I think the upshot was that It didn't like renderDT without a shiny object like df() e.g. renderDT(df()) where df() was a data.frame from a reactive environment. Do you want to update your answer and I will accept? Thank you for all your help – HCAI Mar 12 '21 at 19:06
  • Sure and thanks for sharing your solution, I changed my answer... – Max Teflon Mar 12 '21 at 19:09