如果在tabItem下,则不会显示闪亮的dataTableOutput

我的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",但是仍然无法正常工作。另外,我没有收到任何错误消息。

我想知道是否有人知道我错了哪一步?任何帮助将不胜感激!

beibei0524 回答:如果在tabItem下,则不会显示闪亮的dataTableOutput

问题出在表的位置。我已经在menuItem之外渲染了输入选项。在下面检查此代码

ui <- fluidPage(
  dashboardPage(
    dashboardHeader(title = "My App"),dashboardSidebar(
  sidebarMenu(
    selectInput('location','Please Select a Location',choices= c("A","B","C")),downloadButton(outputId = 'download.csv',lable = "Downlaod"),menuItem("Dashboard",tabName = "dashboard"),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 <- function(input,output,session){

  output$mytable<- DT::renderDataTable({DT::datatable(head(iris))})

  output$downloadcsv <- downloadHandler(
    filename = function(){paste0(sys.Date(),'-mytable.csv')},content = function(file) {write.csv(head(iris),file)}
  )}

  shinyApp(ui=ui,server=server)
本文链接:https://www.f2er.com/3043451.html

大家都在问