[英]Error in match.arg(regions) : 'arg' must be NULL or a character vector
[英]Warning: Error in match.arg: 'arg' must be NULL or a character vector
我試圖在DataTable中選擇單元格並顯示相應的位置/值。 但這似乎不起作用...我從Yihui的示例單元代碼中運行了代碼,但仍然顯示出與從代碼中得到的錯誤相同的錯誤:
以下是我的代碼的一部分。
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"
)
)
任何幫助將非常感激!!
謝謝!!
devtools::install_github('rstudio/DT')
不要使用Cran DT。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.