R Shiny: How to add data tables to dynamically created tabs

二次信任 提交于 2019-12-04 03:30:03

To do what you want, you need to add dataTableOutput to your tabPanel as you dynamically generate them, and then you need to dynamically generate the corresponding renderDataTable.

Do this in your server:

library(DT) # need datatables package
server <- shinyServer(function(input, output, session) {

  output$mytabs <- renderUI({
    nTabs = length(input$decision)
    # create tabPanel with datatable in it
    myTabs = lapply(seq_len(nTabs), function(i) {
      tabPanel(paste0("dataset_",i),
        DT::dataTableOutput(paste0("datatable_",i))       
               )
      })

    do.call(tabsetPanel, myTabs)
  })

  # create datatables
  observe(
    lapply(seq_len(length(input$decision)), function(i) {
      output[[paste0("datatable_",i)]] <- DT::renderDataTable({
        as.data.frame(get(input$decision[i]))
      })
    })  
  )  
})
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!