![](/img/trans.png)
[英]Error in file(file, "rt") : invalid 'description' argument , when calling the function
[英]R shiny: Error in file(file, “rt”) : invalid 'description' argument
如標題所示,我遇到了一個非常常見的錯誤。 但是,它在我閃亮的應用程序中,我不知道發生了什么。
我有一個輸入文件,在第一列中有一個項目列表,在第二列中有.csv文件的名稱。 這些csv文件位於app文件夾的數據目錄中。 觸發應用程序后,要求用戶輸入包含數據集/項目列表的文件。 該列表在第一個選項卡中打開。 我的目的是單擊特定的行,即項目名稱,相應的.csv文件應在第二個選項卡中打開。 第一次單擊時,相應的csv文件在第二個選項卡中打開,但是當我返回第一個選項卡並再次單擊時,它給我以下錯誤:
Error in file(file, "rt") : invalid 'description' argument
我已經附上了所有代碼和相應的文件。
用戶界面
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'))
)
)
)
服務器
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')
})
})
輸入文件:input.csv如下所示:
Project,limma
Hdac3KO,Hdac3KO.csv
Ezh2KO,Ezh2KO.csv
這兩個項目的.csv文件位於應用程序的data /目錄中,如下所示:
這是項目1文件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
這是項目2文件Ezh2KO.csv:
ID,SYMBOL,ENTREZID,ENSEMBL
17278779,NA,NA,NA
17255543,Gm53,193022,NA
17335467,Cdkn1a,12575,ENSMUSG00000023067
17273304,Cbr2,12409,ENSMUSG00000025150
我真的很感謝您的幫助。
我使用的是DT
包的舊版本。 已更新為DT_0.1.32
,現在可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.