0

I am trying to generate HTML items based on data inside a data.frame. The data.frame will be changing from a reactive value, so the loop needs to be reactive as well.

I am struggling with the logic. I found some examples in a shiny dashboard, but I am attempting to do this in a markdown file.

---
title: "test"
runtime: shiny
output: 
  html_document:
    css: "css/styles.css"
---

### {.flex-container}

```{r echo=FALSE}
renderText({
  df <-  data.frame(symbol = 1:10)
  for (i in 1:nrow(df)) {
     div(class="flex-box", style="background-color:#DeF7E9",paste0(df[i,"symbol"]))
  }  

})

```

My css file looks like:

.title {
  visibility: hidden;
}
.flex-box{
  height: 50px;
  width: 50px;
  background-color:#808080;
  margin: 10px;
}

.flex-container {
  display: flex;

}

I am new to R, so be kind..

Cheers, Sody

Edit: getting closer with:

reactive({

divClass = list()  
df <-  data.frame(symbol = 1:10)
  for (i in 1:nrow(df)) {
     divClass[i] = div(class="flex-box", style="background-color:#DeF7E9",paste0(df[i,"symbol"]))
  }  
output$myboxes <- renderUI(divClass)

})

uiOutput("myboxes")

this outputs a list of ten divs as text, like this: div div div div div div div div div div

Aaron Soderstrom
  • 599
  • 1
  • 6
  • 12

1 Answers1

0

How about try this

### {.flex-container}

```{r echo=FALSE}
renderText({
divClass = list()  
df <-  data.frame(symbol = 1:10)
  for (i in 1:nrow(df)) {
     divClass[i] = div(class="flex-box", style="background-color:#DeF7E9",paste0(df[i,"symbol"]))
  }  
divClass
})

```
Not_Dave
  • 491
  • 2
  • 8