我使用动态方式创建UI,但是,某些选项卡是静态的。这对于侧边栏效果很好:
myTabs = lapply(names(datalist) , function(i) {
menuItem(i, tabName = paste0("tab_", i))
})
myTabs = list(menuItem("Welcome", tabName = "welcome"),
myTabs,
menuItem("Country Comparison", tabName = "comparison"),
menuItem("Sources & Raw Data", tabName = "sources")
)
do.call(sidebarMenu, myTabs)
我希望它对于tabItems也能起作用:
myTabs = lapply(names(datalist) , function(i) {
tabItem(tabName = paste0("tab_", i),
uiOutput(paste0("overviewlist",i)),
uiOutput(paste0("box1_",i)),
uiOutput(paste0("box2_",i)),
box(width = 12,
highchartOutput(paste0("spendingpa_",i))
),
uiOutput(paste0("top10print_",i)),
uiOutput(paste0("top10online_",i))
)
})
myTabs = list(tabItem(tabName = "welcome",
box(width = 6)
),
myTabs,
tabItem(tabName = "comparison",
box(width = 6)),
tabItem(tabName = "sources",
box(width = 6))
)
do.call(tabItems, myTabs)
只要我不尝试将某些内容添加到列表中,该代码即可正常工作。然后出现以下错误:Error: Expected an object with class 'shiny.tag'.
我也尝试打印该列表。用lapply
生成后,似乎无法将其他项目添加到myTabs列表中。有人知道如何处理吗?