如果在tabItem下,则不会显示发光的dataTableOutput

问题描述 投票:0回答:1

我的闪亮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下,该应用程序将仅显示“ Widgets选项卡内容”,这是第二个选项卡的内容,并且根本不会填充数据表(尽管下载按钮仍然有效)。

我也曾尝试在class='active'后面添加tabName = "dashboard",但仍然无法正常工作。另外,我没有收到任何错误消息。

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

r shiny shinydashboard
1个回答
0
投票

问题在于桌子的位置。我已经在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)
© www.soinside.com 2019 - 2024. All rights reserved.