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.

3
  • Please don't upload code, error messages, results or data as images for these reasons - and these. Commented Jul 17, 2022 at 12:27
  • Add your tags to a tagList, not a simple vector. Commented Jul 17, 2022 at 12:28
  • Okay thank you, next time I'll respect the rules sorry. Commented Jul 17, 2022 at 13:29

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

2 Comments

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!
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.