【问题标题】:Warning: Error in match.arg: 'arg' must be NULL or a character vector警告:match.arg 中的错误:“arg”必须为 NULL 或字符向量
【发布时间】:2016-01-19 13:22:16
【问题描述】:

我正在尝试选择 DataTable 中的单元格并显示相应的位置/值。 但它似乎不起作用......我从the example cell code from Yihui 运行代码但仍然显示与我从代码中得到的相同错误:

Warning: Error in match.arg: 'arg' must be NULL or a character vector Stack trace (innermost first): 76: match.arg 75: datatable 74: widgetFunc 73: func 72: renderFunc 71: output$x16 4: 3: do.call 2: print.shiny.appobj 1:

以下是我的部分代码。

biTableMatrix 函数 - 它通过 xpos(行)和 ypos(列)将值分配到矩阵/df 中的某个位置。首先它返回一个矩阵,但我认为错误可能是由对象类型引起的(矩阵而不是示例中的 data.frame),所以我将它转换为 data.frame - 对你没有多大帮助......

# The following are in helper.R

travelMeans <- c('02', '04')
prepareTwoMeans <- function(travelMeans) {
  listx <- subset(geodata[geodata$MeanCode==travelMeans[1],], select = -c( AreaFull,MeanName,MeanFull))
  listx <- listx[order(listx$Percentage),] 

  listy <- subset(geodata[geodata$MeanCode==travelMeans[2],], select = -c( AreaFull,MeanName,MeanFull,AreaCode))
  listy <- listy[order(listy$Percentage),] 

  listx$xpos <- seq(length=nrow(listx))
  listy$ypos <- seq(length=nrow(listy))

  listx <- merge(listx, listy, by.x = c("AreaName"), by.y = c("AreaName"), all=TRUE)
  return(listx)  
}

# This function generates the two-way table of two travel means
biTableMatrix <- function(travelMeans) {
  fullList <- prepareTwoMeans(travelMeans)
  len <- length(fullList$AreaName)
  biTableMat <- matrix(data = "", nrow = len, ncol = len, dimnames = list(seq(length = len), seq(length = len)))#, 

  for (n in 1:len) {
    x <- fullList$xpos[n]
    y <- fullList$ypos[n]
    biTableMat[x,y] <- as.character(fullList$AreaName[n]) #fullList$AreaCode[n]
  }

  return(as.data.frame(biTableMat) )
}

# The following are in server.R
  biTable <- reactive({
    return(biTableMatrix(input$travelMeans))
  })

  output$biTable <- DT::renderDataTable({
    DT::datatable(
     biTable()
     , selection = list(mode = "single", target = "cell")
     , extensions = list("Scroller", "RowReorder")
     , options = list(
        scrollX = 500
      , scrollY = 700
      , rowReorder = FALSE
     )      
   )}
    , options = list(
      searchHighlight = TRUE
    )
  )

 output$biTableText <- renderPrint(input$biTable_cells_selected$value)

供参考,这是我的ui.R

#Definte UI for the application
ui <- fluidPage(
sidebarPanel(
    # The following part is groupCheckBox format for the travelMeans
    checkboxGroupInput(
      "travelMeans"
      , label = "Select the mean below:"
      , choices = meanChoices
      , selected = NULL
    )

    , br()
  ),

  #Show the map
  mainPanel(
    tabsetPanel(#type = "tabs",
        tabPanel("Single-Mean Table", DT::dataTableOutput("onetable"), hr())

      , tabPanel("Two-way table", DT::dataTableOutput("biTable"), hr(), verbatimTextOutput("biTableText"))
    )

    , position="center"
   , height= "auto"
  )
)

任何帮助将不胜感激!

谢谢!!

【问题讨论】:

    标签: r statistics shiny


    【解决方案1】:
    devtools::install_github('rstudio/DT')
    

    不要使用 cran DT。

    【讨论】:

    • 对不起,我的意思是你可以使用来自 github 的 DT,因为它是 DT 最发达的版本。 CRAN DT 更新缓慢。
    猜你喜欢
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多