【发布时间】:2018-09-08 13:12:40
【问题描述】:
我正在尝试在模块中插入动态调用insertTab() 函数的选项卡。出于某种原因,我的方法不起作用。我想问题是我如何将tabsetPanel id 和现有tabPanel 的value (旁边应该添加tab)传递给模块。
actionButUI = function(id, label=NULL) {
ns = NS(id)
tagList(
actionButton(ns("button"), label = label)
)
}
actionBut = function(input, output, session, tabsetPanel_id, target) {
observeEvent(input$button, {
insertTab(
inputId = tabsetPanel_id(),
tabPanel(
"Dynamic", "This a dynamically-added tab"
),
target = target
)
})
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButUI("append_tab", "Insert Tab")
),
mainPanel(
tabsetPanel(id = "tabs",
tabPanel("Hello", "This is the hello tab"),
tabPanel("Bar", "This is the bar tab")
)
)
)
)
server <- function(input, output, session) {
callModule(actionBut, "append_tab", reactive({input$tabs}), "Bar")
}
shinyApp(ui, server)
【问题讨论】:
-
您的代码中有一些语法问题我没有在我的回答中解决。您应该将
"tabs"作为tabsetPanel_id参数传递并在模块中以tabsetPanel_id的身份访问它,而不是tabsetPanel_id()