R Shiny dynamic tab number and input generation

前端 未结 1 1894
难免孤独
难免孤独 2021-01-17 00:04

I\'ve got an issue with my current shiny code. I have to generate a dynamic number of tabs depending on the results of a given function (that part works fine). Then, I want

相关标签:
1条回答
  • 2021-01-17 00:34

    Here's a solution that seems to work. I'm using lapply to create the tabs. Let me know if it works for what you need.

    library(shiny)
    
    ui <- pageWithSidebar(
      headerPanel("xxx"),
      sidebarPanel(),
      mainPanel(
        do.call(tabsetPanel, c(id='tab',lapply(1:5, function(i) {
          tabPanel(
            title=paste0('tab ', i), 
            textOutput(paste0('out',i))
          )
        })))
      )
    )
    
    server <- function(input, output) {     
      lapply(1:5, function(j) {
        output[[paste0('out',j)]] <- renderPrint({
          paste0('generated out ', j)
        })
      })
    }
    
    shinyApp(ui, server)
    
    0 讨论(0)
提交回复
热议问题