我的Shiny APP具有一个简单的结构,如下所示:
ui <- fluidPage(
dashboardPage(
dashboardheader(title = "My App"),dashboardSidebar(
sidebarMenu(
menuItem("Dashboard",tabName = "dashboard",selectInput('location','Please Select a Location',choices= c("A","B","C")),downloadButton(outputId = 'download',lable = "Downlaod"),menuItem("Widgets",tabName = "widgets",badgeLabel = "new",badgeColor = "green")
)),# dashboardBody first try (works no problem):
dashboardBody(DT::dataTableOutput(outputId = 'mytable'))
# dashboardBody second try (data table does not appear):
dashboardBody(
tabItems(
tabItem(tabName = "dashboard",DT::dataTableOutput(outputId = 'mytable')),tabItem(tabName = "widgets",h2("Widgets tab content"))
)))
server <- shinyServer(function(input,output,session){
output$mytable<- DT::renderDataTable({```some calculation```})
output$downloadcsv <- downloadHandler(
filename = function(){paste0(sys.Date(),'-mytable.csv')},content = function(file) {write.csv(```the table from renderDataTable step```,file)}
)}
如您所见,该应用程序包含两个不同的“页面”,其中第一个是取决于selectInput
的数据表。
如果我不使用tabItem
包装它,那么我的应用程序将运行完美。但是,一旦我将其写入tabItem
下,该应用程序仅显示“窗口小部件标签内容” ,这是第二个标签的内容,并且根本不会填充数据表(在下载时按钮仍然有效)。
我也尝试在class='active'
后面添加tabName = "dashboard"
,但是仍然无法正常工作。另外,我没有收到任何错误消息。
我想知道是否有人知道我错了哪一步?任何帮助将不胜感激!