如何在下拉菜单中的闪光应用程序内部的子目录填充csv文件。 [英] How to populate csv files of a subdirectory inside shiny app in drop-down menu.?
问题描述
可能的重复
当您调用 list.files
,你需要指定你想要列出的文件的路径,默认路径是当前目录,这将是你有 ui.R
和 server.R
文件。
尝试:
filenames< - list.files(path =data,pattern =\\.csv)
您可以将此行放在 ui中
文件。 shinyUI(...)
.R
对于代码的第二部分,它看起来像是要清理数据,已将 inputdata
更改为 clean_data
以使其更清楚):
clean_data< - reactive({
#get the data
df1< - dataInput()
if(is.null df1))
return(NULL)
df1 []< - lapply(df1,as.character)
#looks用于只有零个或多个空格的行斜杠在第3列并删除它们
df1 < - df1 [!grepl($ * ^ | /,df1 [,3]),]
df1
})$ b b
#do你想要的数据,用于expample将它作为另一个表
输出$ annotation< - renderDataTable({
withProgress(message ='正在加载数据。 。 。',{
clean_data()
})
})
b $ b
此外,查看您的输入文件示例,您有很多 Gene title
有逗号,如果您的 csv
文件是一个逗号。
Possible duplicate
Cannot populate drop down menu dynamically in R shiny
I have a small shiny app with some drop-down option for user. I created a subdirectory say data
inside shiny app containing csv files to appear in the drop-down menu. I used the below code, but i am not able to access the files in the data
subdirectory.
On ui.r:
filenames <- list.files(pattern="\\.csv")
selectInput(inputId="dataset",label= "Choose platform annotation file",filenames)
server.r:
dataInput <- reactive({
if (grepl("[/\\\\]", input$dataset)) {
stop("Invalid dataset")
}
read.csv(file.path("data", input$dataset))
})
output$annotation <- renderDataTable({
withProgress(message = 'Loading Data . . .', {
dataInput()
})
})
The above code allows me to access the csv files if they are inside the app as my server.r
and ui.r
is , not in the separate subdirectory inside shiny app.
I also want to know is this the correct way to access the data of above code, as i am not able to access the data further in my below code.
inputdata <- reactive({
df1 <- data.frame()
df1 <- dataInput()
if (is.null(df1))
return(NULL)
df1[] <- lapply(df1, as.character)
df1 <- df1[df1[,3]!='',]
df1 <- df1[!grepl('[/]', df1$Gene.Title),]
})
I tried this also
filenames <- list.files(pattern="\\.csv$data") ## data is my folder inside shiny app.
to access thedata
subdirectory inside shiny app with csv files, but not able to do.
Edited: Input file example
ID Gene Title Gene Symbol
1007_s_at discoidin domain receptor tyrosine kinase 1 DDR1
1053_at replication factor C (activator 1) 2, 40kDa 7-Mar
117_at heat shock 70kDa protein 6 (HSP70B') HSPA6
121_at paired box 8 PAX8
1255_g_at guanylate cyclase activator 1A (retina) GUCA1A
1294_at ubiquitin-like modifier activating enzyme 7 UBA7
1320_at protein tyrosine phosphatase, non-receptor PTPN21
1405_i_at chemokine (C-C motif) ligand 5 CCL5/CCL6
1431_at
1438_at EPH receptor B3 EPHB3
1487_at estrogen-related receptor alpha ESRRA
1494_f_at cytochrome P450, family 2 CYP2A6/CYP2
When you call list.files
, you need to specify the path you want to list the files of, the default path is the current directory, which would be the directory where you have the ui.R
and server.R
file.
Try:
filenames <- list.files(path="data",pattern="\\.csv")
You can put this line before the shinyUI(...)
in your ui.R
file.
For the second part of your code, it looks like you want to clean up the data, you could do (I changed inputdata
to clean_data
to make it clearer):
clean_data <- reactive({
#get the data
df1 <- dataInput()
if (is.null(df1))
return(NULL)
df1[] <- lapply(df1, as.character)
#looks for lines that have only zero or more blanks or a slash in column 3 and removes them
df1 <- df1[!grepl("$ *^|/",df1[,3]),]
df1
})
#do what you want with the data, for expample render it as another table
output$annotation <- renderDataTable({
withProgress(message = 'Loading Data . . .', {
clean_data()
})
})
Also, looking at your input file examples you have a lot of Gene title
that have commas, this might cause issues if your the separator in your csv
file is a comma.
这篇关于如何在下拉菜单中的闪光应用程序内部的子目录填充csv文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!