0

I'm really new to R/Shiny, I'm working on a project and I'm having a problem. Indeed, according to what I learned on the documentation, the renderTable function makes it possible to generate a datatable from a dataframe for example but, I do not wish to use this function because, I myself would like to create the structure of my HTML table and I would like for example that it looks like an invoice where the rows, the columns are for example merged etc... except that with renderTable it is not possible to do it at least, not to my knowledge. enter image description here

When I add the loop this is what happensenter image description here

Finally, here is how I proceed: enter image description here

enter image description here

The highlighted line (1578) is where I add the new lines generated above so when I comment on it the header is displayed normally.

  • Please don't upload code, error messages, results or data as images for [these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) - and [these](https://xkcd.com/2116/). – Limey Jul 17 '22 at 12:27
  • Add your tags to a `tagList`, not a simple vector. – Limey Jul 17 '22 at 12:28
  • Okay thank you, next time I'll respect the rules sorry. – armel sauvy Jul 17 '22 at 13:29

1 Answers1

1

You can do something like this to generate the body:

library(htmltools)

rows <- vector("list", length = nrow(dat))

for(i in 1:nrow(dat)){
  rows[[i]] <- withTags(
    tr(
      td(dat[i, "column1"]),
      td(dat[i, "column2"])
    )
  )
}

body <- do.call(tags$tbody, rows)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • Thank you for this solution, it already solves 80% of my problem except that I have the following error: "Warning: Error in [: object of type 'closure' is not subsettable [No stack trace available]" but, if I replace for example td(dat[i, "column1"]) by td("Hello"), everything works normally whereas, I do a print(td (dat[i, "column1"]),) before entering rows[[i]] <- withTags( ...) it displays the result well! – armel sauvy Jul 17 '22 at 13:24
  • Thanks again for your proposal finally, it solved my problem, I just adapted by getting the dat[i, "column1"] values ​​in intermediate variables before passing them in td(myVar). My problem is solved thanks to you! – armel sauvy Jul 17 '22 at 13:38