简体   繁体   中英

R shiny: Error in file(file, “rt”) : invalid 'description' argument

I am getting a very common error as the title indicates. However, it is in my shiny app and I don't know what's going on.

I have a input file that has a list of projects in one column and names of .csv files in the second column. These csv files are in the data dir of the app folder. When the app is fired, the user is asked to input the file with list of datasets/projects. That list is opened in the first tab. My aim is to click on a particular row ie project name and the corresponding .csv file should open in the second tab. When I click the first time, the corresponding csv file opens in the second tab, but when I go back to the first tab and click again, it gives me the following error:

Error in file(file, "rt") : invalid 'description' argument

I have attached all my code and corresponding files.

ui.R

dashboardPage(
  dashboardHeader(title = 'Title',titleWidth = 500),

  dashboardSidebar(width = 500,
    fluidRow(
      column(6, div(style = "height:10px"), 
             fileInput(inputId = 'inputdataset', label = 'Input Datasets', accept = c('csv','tsv','txt')))
    )
  ),

  dashboardBody(

    tabsetPanel(type="tabs", id = "tabvalue",
                tabPanel(title = "Project List", value='tab',DT::dataTableOutput('projects')),
                tabPanel(title = "Input Table", value = 'tab1', DT::dataTableOutput('table'))
    )
  )
)

server.R

library(shiny)
library(shinydashboard)

options(shiny.maxRequestSize = 30*1024^2)

shinyServer(function(input, output, session){

  # read in initial data input.csv i.e. a file containing list of projects
  # this file has a column of projects and a column of corresponding csv files
  # the third column in the table i.e. 'limma' specifies the names of the csv file
  # the data directory of the app folder contains those .csv files
  datainput <- reactive({
    infile <- input$inputdataset
    if(is.null(infile))
      return(NULL)
    read.csv(infile$datapath,check.names=F)
  })

  # output list of projects in projects tab
  # you can select any of the projects
  output$projects <- DT::renderDataTable({
    DT::datatable(datainput(), selection = 'single')
  })

  # go to tab1 when a project is selected 
  observe({
    s <- input$projects_rows_selected
    if(length(s)){
      updateTabsetPanel(session = session, inputId = "tabvalue", selected = 'tab1')
    }
  })

  # when a project is selected, the corresponding limma file is opened
  datasetInput <- reactive({
    d <- datainput()
    s <- input$projects_rows_selected
    dat <- d[s, , drop = FALSE]
    limma <- as.character(dat$limma)
    file <- paste('data/',limma,sep='')
    dd <- read.csv(file=file)
    dd
  })

  # output data for selected project in tab1
  output$table <- DT::renderDataTable({
      DT::datatable(datasetInput(),
                    selection = 'single')
  })
})

The input file: input.csv looks like this:

Project,limma
Hdac3KO,Hdac3KO.csv
Ezh2KO,Ezh2KO.csv

.csv files for the two projects are in the data/ dir of the app as follows:

This is project 1 file, Hdac3KO.csv:

ID,SYMBOL,ENTREZID,ENSEMBL
17278840,Mir376a,723855,NA
17350196,Scgb3a2,117158,ENSMUSG00000038791
17278838,Mir376b,723934,ENSMUSG00000076006
17326069,Retnla,57262,ENSMUSG00000061100
17315245,Krt18,16668,ENSMUSG00000023043

This is project 2 file, Ezh2KO.csv:

ID,SYMBOL,ENTREZID,ENSEMBL
17278779,NA,NA,NA
17255543,Gm53,193022,NA
17335467,Cdkn1a,12575,ENSMUSG00000023067
17273304,Cbr2,12409,ENSMUSG00000025150

I'd really appreciate any help.

I was using an older version of package DT . Updated to DT_0.1.32 and it is working fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM