-1

I'm trying to make/ print/ show table with Shiny R using for loop, however my for loop doesn't return HTML. Could you help me to find out what's wrong with my for loop? Thank you in advance!

div(style="font-size: 9pt; font-family:calibri;",
    tags$table(
      tags$caption("Market Split"),
      tags$tr(
        tags$th(names(dpe1)[1]),
        tags$th(names(dpe1)[2])
      ),
      for (i in 1:nrow(dpe1)){
        tags$tr(
          tags$td(dpe1[i,1]),
          tags$td(dpe1[i,2])
        )}
    ))

as a result:

<div style="font-size: 9pt; font-family:calibri;">
  <table>
    <caption>Market Split</caption>
    <tr>
      <th>Planning.Area</th>
      <th>Reporting.Country</th>
    </tr>
  </table>
</div>
  • Possible duplicate of [R Shiny - Display multiple plots selected with checkboxGroupInput](https://stackoverflow.com/questions/41201192/r-shiny-display-multiple-plots-selected-with-checkboxgroupinput) – amrrs Nov 07 '17 at 09:21
  • 1
    With Shiny, you build data frames and other R objects, that are passed to Shiny functions (e.g. `renderDataTable`, see https://shiny.rstudio.com/articles/datatables.html) that are responsible for rendering the HTML and JS (latter for interactivity). I suggest you go through some tutorials on Shiny. – MrGumble Nov 07 '17 at 09:21
  • thanks for the answer, this I've got. my question was rather how to handle it with htmltools. – user3764626 Nov 07 '17 at 11:05

1 Answers1

0
You can use DT::renderDataTable option--

##output$contents1 <- DT::renderDataTable({
##Create Dataframes using loop

##Show table in main panel using datatable(Dataframe)

##return(Dataframe)##This dataframe you can use in your script for further 
use.

## })
mehakVT
  • 167
  • 1
  • 8
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Isma Nov 07 '17 at 12:32