As a newcomer to Shiny, I'm looking for some guidance for rendering the elements in a list of tibbles.
I followed this thread and was able to render a fixed number of tibbles iteratively with uiOutput.
I'm wondering if anyone could point me to an example in which the layout of the tables can be changed so they are not simply stacked on top of each other.
My goal is to to show a title and caption for each one, of which the title would come from the names of the list objects.
here is small reproducible example, with a list of three tibbles rendered as reacttables.
I think an option can be generate the html in renderUI, so you can have all your data (table, title, caption) in a tibble, and then with pmap, generate the html part: a div containting the title, the reactable and caption for every table and send that to the uiOutput.
library(shiny)
library(purrr)
library(dplyr)
library(reactable)
library(htmltools)
# input <- list(ntables = 4)
ui <- fluidPage(
mainPanel(
sliderInput("ntables", "# tables", min = 1, max = 4, value = 1),
uiOutput("tables", class = "row")
)
)
server <- function(input, output) {
output$tables <- renderUI({
n <- input$ntables
tablas <- map(1:n, function(i) as_tibble(matrix(rnorm(10 * i), ncol = i)))
titulos <- paste("titulo", 1:n)
captions <- paste("caption", 1:n)
tibble(
tbl = tablas,
tle = titulos,
cap = captions
) %>%
pmap(function(tbl, tle, cap){
tags$div(
class = "col-sm-4", # given by bootstrap
tags$h1(tle),
reactable(tbl),
tags$em(cap)
)
})
})
}
shinyApp(ui = ui, server = server)
Hi @Luis. I would suggest you layout a div in ui and add individual ui for each reactable by insertUI with your layout design (title or caption). And render each table with renderReactable. Hope it can help.
thanks @raytong and @jbkunst!
both of your approaches worked for my data and they are quite similar
now I'm looking into modifying the contents of each div to customize the table layouts and add some space between them.