这是模块答案,我在每个选项卡中添加了一个表。
library(shiny)
library(shinyWidgets)
library(dplyr)
addTab <- function(id) {
ns <- NS(id)
tagList(
selectInput(ns("select"),
"Choose",
choices = colnames(mtcars)),
tableOutput(ns("table"))
)
}
moduleTable <- function(input, output, session){
output$table <- renderTable({
select(mtcars, input$select)
})
}
ui <- navbarPage(position = "static-top",
title = "foo",
id = "tabs",
tabPanel(title = "More",
icon = icon("plus"),
fluidRow()
)
)
server <- function(input, output) {
count <- reactiveValues(val=1)
observeEvent(input$tabs, {
if (input$tabs == "More"){
name <- paste0("Name ", count$val)
insertTab(inputId = "tabs",
tabPanel(title = name,
addTab(paste0("select", count$val))
),
target = "More",
position = "before",
select = TRUE)
callModule(moduleTable, paste0("select", count$val))
count$val <- count$val+1
}
})
}
shinyApp(ui = ui, server = server)