条件renderUI和tabPanel

时间:2013-12-11 15:19:20

标签: r shiny

我在server.R中有以下代码,我收到如下所示的错误。我看到其他examples工作正常,我不知道为什么这不起作用?

   output$mytabs = renderUI({
if(some_condition)
        myTabs = c(tabPanel('Title 1', h4("Tab 1"), htmlOutput("tab_data_1")),
                   tabPanel("Title 2",h4("Tab 2"), verbatimTextOutput("tab_data_2")))
if(some_other_condition)
        myTabs = c(tabPanel('Title 3', h4("Tab 4"), htmlOutput("tab_data_3")),
                   tabPanel("Title 2",h4("Tab 2"), verbatimTextOutput("tab_data_2")))

        do.call(tabsetPanel, myTabs)
# I also tried
# do.call(tabsetPanel, c("tabpanel", myTabs))
      })

Error in `*tmp*`$attribs : $ operator is invalid for atomic vectors

1 个答案:

答案 0 :(得分:2)

这应该有效:

do.call(tabsetPanel, list(myTabs))

甚至更简单:

tabsetPanel(myTabs)