闪亮:insertTab与模块

时间:2018-03-29 14:15:48

标签: module shiny

我正在尝试动态调用模块中的insertTab()函数。出于某种原因,我的方法不起作用。我想问题是我如何将tabsetPanel ID和现有value的{​​{1}}(旁边应添加tabPanel)传递给模块。

tab

2 个答案:

答案 0 :(得分:2)

命名空间似乎存在问题。以下修改解决了问题

tabsetPanel(id = "append_tab-tabs",
            tabPanel("Hello", "This is the hello tab"),
            tabPanel("Bar", "This is the bar tab"))

insertTab函数尝试在模块命名空间而不是全局元素中添加ui元素。如果您查看insertTab的源代码,您会看到

inputId <- session$ns(inputId)

导致此行为。

另一种方法是将session变量从主应用传递到insetTab而不是模块的session

actionBut = function(input, output, session, tabsetPanel_id = "tabs", target) {
  ## do some environment hacking: Get the `session` variabe from the
  ## environment that invoked `callModule`.
  parentSession <- get("session", envir = parent.frame(2))

  observeEvent(input$button, {
    insertTab(
      inputId = tabsetPanel_id, 
      tabPanel(
        "Dynamic", "This a dynamically-added tab"
      ),
      target = target,
      session = parentSession
    )
  })
}

如果您使用嵌套模块,这种方法会变得非常混乱。

答案 1 :(得分:1)

InsertTab函数的替代方法,您可以遵循Ramnath解决方案here

我把它变成了模块。

SELECT c.PK_CustomerID, c.FirstName, c.LastName, u.Email
   ,COUNT(*) OVER (PARTITION BY c.firstname, c.lastname) as instance
FROM Customers c, Users u
WHERE c.Location = 2 AND c.FK_UserID = u.PK_UserID
ORDER BY c.PK_CustomerID ASC