I have a shiny
app in which I would like to print multiple tables. The catch is, I do not know how many tables I will have in advance - it depends on the data. E.g. if the variable "X" has 5 levels, I want to output 5 tables - one for each level of the variable.
To generate a table, I call a function inside renderTable()
in server.R
and assign it to an output
slot like this:
output$tablePyramid <- renderTable ({
tableGeneratingFunction(argument1, argument2, ...)
})
If I put more than one "tableGeneratingFunction" inside the renderTable()
, it only returns the last table generated. So it seems it's only one table per output
slot. I guess I could handle this in the server.R
file, assigning dynamically as many output
slots as needed.
But I also have to list all outputs in the ui.R
file. Example excerpt for two tables:
mainPanel(
tabsetPanel(
... some code
tabPanel(title="Proportions",
tableOutput("tablePyramid"),
tableOutput("tablePyramid2")
),
... some more code
Do I have to list each table in its own tableOutput
function or is there a more elegant way to proceed, since I do not know in advance how many tableOutput
s I will need?