【问题标题】:Shiny dataTableOutput won't show up if its is under tabItem如果它在 tabItem 下,闪亮的 dataTableOutput 将不会显示
【发布时间】:2019-11-24 01:12:21
【问题描述】:

我的 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 下编写它,该应用程序只显示 "Widgets tab content" 这是第二个选项卡的内容并且根本不填充数据表(而下载按钮仍然作品)。

我也试过在tabName = "dashboard"后面加class='active',但还是不行。另外,我没有收到任何错误消息。

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

【问题讨论】:

  • 您能否更正您在应用中渲染“output$downloadcsv”的位置。

标签: r shiny shinydashboard


【解决方案1】:

问题在于桌子的位置。我已经在 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)

【讨论】:

    猜你喜欢
    • 2018-12-21
    • 2017-09-30
    • 2019-05-11
    • 1970-01-01
    • 2018-12-05
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多