首页 > 解决方案 > 警告:dataTableOutput 中的错误:未使用的参数(高度 =“自动”)

问题描述

使用 dataTableOutput ( https://github.com/rstudio/DT )看到不一致的结果。当我从 R 控制台开始闪亮时,我第一次运行应用程序时,高度参数dataTableOutput()会导致应用程序崩溃。如果我然后 CTRL-C 停止闪亮,然后闪亮::runApp(),那么应用程序从此按预期工作。不超过高度在当地是可以的。该框被填充并自动调整其高度。但是,当在 shinyapps.io 上加载应用程序时,该框始终是空的并且高度很小(比如说 60 像素)。无论我在shinyapps.io 上做什么,如果高度是,例如,height=300那么应用程序总是会崩溃。没有 CTRL-C 将在 shinyapps.io 上工作。有时,当存在“height=300”时,应用程序会拒绝在本地启动,但如果我注释掉dataTableOutput完全,重新运行 shiny::runApp(),然后在不重新启动闪亮的情况下恢复 dataTableOutput,然后应用程序加载正常。

错误:

Warning: Error in dataTableOutput: unused argument (height = "200")
  100: h
   99: .handleSimpleError
   98: dots_list
   97: div
   96: dots_list
   95: div
   94: dots_list
   93: div
   92: box
   91: dots_list
   90: div
   89: fluidRow
   88: dots_list
   87: div
   86: column
   85: dots_list
   84: div
   83: fluidRow
   82: dots_list
   81: div
   80: tabItem
   79: lapply
   78: tabItems
   77: dots_list
   76: tags$section
   75: dots_list
   74: div
   73: dashboardBody
   72: tagAssert
   71: dashboardPage
   70: ..stacktraceon..
   69: eval
   68: eval
   67: sourceUTF8
   66: func
   65: uiHandlerSource
   64: handler
   63: handler
   62: handler
   61: handlers$invoke
   60: withCallingHandlers
   59: domain$wrapSync
   58: promises::with_promise_domain
   57: captureStackTraces
   56: withCallingHandlers
   55: withLogErrors
   54: withCallingHandlers
   53: force
   52: withVisible
   51: withCallingHandlers
   50: domain$wrapSync
   49: promises::with_promise_domain
   48: captureStackTraces
   47: doTryCatch
   46: tryCatchOne
   45: tryCatchList
   44: tryCatch
   43: do
   42: hybrid_chain
   41: force
   40: withVisible
   39: withCallingHandlers
   38: domain$wrapSync
   37: promises::with_promise_domain
   36: captureStackTraces
   35: doTryCatch
   34: tryCatchOne
   33: tryCatchList
   32: tryCatch
   31: do
   30: hybrid_chain
   29: handler
   28: func
   27: compute
   26: doTryCatch
   25: tryCatchOne
   24: tryCatchList
   23: tryCatch
   22: rookCall
   21: <Anonymous>
   20: evalq
   19: evalq
   18: doTryCatch
   17: tryCatchOne
   16: tryCatchList
   15: doTryCatch
   14: tryCatchOne
   13: tryCatchList
   12: tryCatch
   11: execCallbacks
   10: run_now
    9: service
    8: serviceApp
    7: ..stacktracefloor..
    6: withCallingHandlers
    5: domain$wrapSync
    4: promises::with_promise_domain
    3: captureStackTraces
    2: ..stacktraceoff..
    1: shiny::runApp

代码(两个示例框,尽管一个足以显示问题):

dashboardPage(
  dashboardHeader(title = 'Energy comparison'),
  dashboardSidebar(
    sidebarMenu(
      ...
      menuItem('Stacked', tabName = 'table', icon = NULL)
    )
  ),
  dashboardBody(
    tabItems(
      ...
      tabItem(
        tabName = 'table',
        fluidRow(
          column(6,
            fluidRow(
              box(title = 'Annual energy by source',
                solidHeader = TRUE, status = 'primary', width = 12,
                dataTableOutput('tab1') # Always works locally.
                                        # Doesn't crash shinyapps.io
                                        # but always show a tiny box
                                        # with no data.
              )
            )
          ),
          column(6,
            fluidRow(
              box(title = 'Annual energy by source %',
                solidHeader = TRUE, status = 'primary', width = 12,
                dataTableOutput('tab2', height="auto")
                  # height = "auto" or "300"
                  # Causes error sporadically locally.
                  # Can get it working locally by removing "height=..."
                  # then reloading the page while shiny is running.
                  # But this always crashes on shinyapps.io.
              )
            )
          )
        )
      )      
    )
  )
)

标签:数据表输出

标签: rshinydatatableshinyapps

解决方案


有两个函数dataTableOutput,一个存在于shiny没有height参数的包中,另一个存在于DT包中。我不知道您是否正在加载DT包,但最好明确提及您想dataTableOutputDT包中使用。

DT::dataTableOutput('tab2', height="auto")

推荐阅读