Скажите, что у меня есть следующее - принимая к сведению myList
:
library(shiny)
myList <- list(
first_element = tibble(a = 1, b = 2),
second_element = tibble(a = 4:5, e = 7:8),
third_element = tibble(a = c("one", "two", "three"), x = c("another", "another one", "another two"))
)
ui <- fluidPage(
titlePanel("A Title"),
verbatimTextOutput("pretty_output")
)
server <- function(input, output, session) {
output$pretty_output <- renderPrint({
myList
})
}
shinyApp(ui, server)
Это приводит к:
![Shiny App](https://i.stack.imgur.com/NWde3.png)
Я хотел бы представить myList
как отдельные элементы renderTable
или renderDataTable
программно.Следующее иллюстрирует подход грубой силы, но я ищу что-то более гибкое, более СУХОЕ, используя цикл for, lapply
, purrr::map()
и / или что-то еще.
ПРИМЕЧАНИЕ. Длина myList
должна быть неизвестной.
library(shiny)
library(DT)
myList <- list(
first_element = tibble(a = 1, b = 2),
second_element = tibble(a = 4:5, e = 7:8),
third_element = tibble(a = c("one", "two", "three"), x = c("another", "another one", "another two"))
)
ui <- fluidPage(
titlePanel("A Title"),
dataTableOutput("dt_01"),
dataTableOutput("dt_02"),
dataTableOutput("dt_03")
)
server <- function(input, output, session) {
output$dt_01 <- renderDataTable({
datatable(myList[[1]], caption = names(myList[1]))
})
output$dt_02 <- renderDataTable({
datatable(myList[[2]], caption = names(myList[2]))
})
output$dt_03 <- renderDataTable({
datatable(myList[[3]], caption = names(myList[3]))
})
}
shinyApp(ui, server)