2017-11-11 357 views
0

ShinyのサーバーでrenderTableの出力があり、次のコードでファイナルテーブルの名前を変更しようとしています:2次元未満のオブジェクトで 'colnames'を設定しようとするとエラーになるR

output$tubeArrival <- renderTable({ 

#GET request and convert JSON to a dataframe 
data <- GET(url) 
text_data <- content(data,as = 'text') 
json_data <- fromJSON(text_data) 

json_data$timeToArrive = minSec(json_data$timeToStation) 
json_data$bound <- substr(as.character(json_data$platformName),1,1) 
json_data$platform <- substrRight(as.character(json_data$platformName),1) 
cleaned_data <- subset(json_data,boundDirect(json_data$bound) == input$direction) 

final_data <- cleaned_data[c('platform','towards','timeToArrive','currentLocation')] 
colnames(final_data) <- c('Plat.','To','ETA','Current Loc.') 

final_data <- final_data}) 

しかし、次のエラー表示されます。

Warning: Error in colnames<-: attempt to set 'colnames' on an object with less than two dimensions 

は非常に任意の助けに感謝!事前に

おかげで、エラーがスローされ何行

答えて

0

トミー? callstackと問題のある行を取得するには、traceback()を試してください。

ちょうどそれが目の当たりにして、(空の)行の位置と列の位置の間にコンマがないようです。その第三に、最後の行は、あなたがこのような何かをすればところで、列の名前を変更することは安全です

final_data <- cleaned_data[, c('platform','towards','timeToArrive','currentLocation') 

に変更する必要があります。行が見つからない場合は、エラーメッセージが改善されるはずです。

cleaned_data <- json_data %>% 
    dplyr::filter(boundDirect(.$bound) == .$direction) %>% 
    dplyr::rename_(
    'Plat.'   = 'platform', 
    'To'   = 'towards', 
    'ETA'   = 'timeToArrive', 
    'Current Loc.' = 'currentLocation' 
) 
+0

Thx for this!できます –

関連する問題