Boş tablo içeren parlak R renderDataTable

Sep 08 2020

Bir veri tablosunu yalnızca veri mevcutsa parlak olarak oluşturmanın en iyi yolu nedir? Şu anda, Bright'a NULL olsa bile bir veri tablosu oluşturmasını söylüyorum çünkü şu hatayı alıyorum.

    Warning in file(file, "rt") :
    cannot open file '\': No such file or directory
    Warning: Error in file: cannot open the connection

Kodum şu şekilde bölünmüş durumda, kullanıcı bir csv dosyası seçtikten sonra verileri okuyorum. Bir kullanıcı bir csv dosyası seçtikten sonra, hata kaybolur ve her şey yolunda gider. Shiny'e geçerli bir dosya seçilene kadar bir veri tablosunu görüntülememesini nasıl söyleyebilirim?

filedata <- reactive({
  if (is.null(input$file_selector)){ # User has not uploaded a file yet return(NULL) } else { read.csv(paste0(parseDirPath(c(home = 'C:\\Users\\Ruben'), file_dir()),'\\',input$file_selector),skip=1)}
})

output$filetable <- renderDataTable({
  filedata()
})

Dosya verisi <- ... işlevinde $ filetable <- .... kodunu read.csv ... satırından sonra koymayı denedim, ancak bu da çalışmıyor. Burada başka ne yapmalıyım?

Yanıtlar

1 Gourab Sep 08 2020 at 09:09

Req () işlevini kullanabilirsiniz, bu, dosyanın mevcut olup olmadığını kontrol edecek ve ardından prosedür koduna gidecektir.

filedata <- reactive({
  file <-input$file_selector
  req(file)
  read.csv(paste0(parseDirPath(c(home = 'C:\\Users\\Ruben'), file_dir()),'\\',file),skip=1)}
})
1 YBS Sep 08 2020 at 08:55

Lütfen req()aşağıda gösterildiği gibi kullanın

filedata <- reactive({
  req(input$file_selector) read.csv(paste0(parseDirPath(c(home = 'C:\\Users\\Ruben'), file_dir()),'\\',input$file_selector),skip=1)
})