This a a way to create a number of tables in the UI and assign them each a dataset:
library(shiny)
library(plotly)
ui <- fluidPage(
uiOutput("allTables")
)
server <- function(input, output, session) {
#Create fake data tables
nTables = 3
myData = lapply(1:nTables, function(x) {data.frame(x = 1:10, y = runif(10))})
#Create the UI for the tables
output$allTables = renderUI({
eval(parse(text =
paste0("tagList(",
paste0("tableOutput('table", 1:nTables,"')", collapse = ", "),
")")))
})
#Assign the output to the UI
eval(parse(text = paste0("output$table", 1:nTables, "<-renderTable(myData[[",1:nTables,"]])")))
}
shinyApp(ui, server)
It doesn't look very readable as you have to use string evaluation to get the effect you want, but it does work...
If you would tell us a bit more of your exact goal, I think there might be more elegant ways to solve this issue... normally you know beforehand how many tables you'll have and what data goes in it, but maybe your case is special
Thank you very much for the swift reply PJ. This code could help my goal but the code outputs all the datasets at the same time.
Is there a way on can assess a single dataset out of the three one at a time in the UI?
Also my goal is to create a dashboard where each tabItem displays the one of the list of dataframes. Thus instead of typing the code all over again, each tabItem outputs one of dataframe.