如何在下拉菜单中的闪光应用程序内部的子目录填充csv文件。 [英] How to populate csv files of a subdirectory inside shiny app in drop-down menu.?

查看:418
本文介绍了如何在下拉菜单中的闪光应用程序内部的子目录填充csv文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复





我有一个小的闪亮的应用程序,有一些下降的动态在下拉菜单动态在闪光 -down选项。我在一个包含csv文件的闪亮应用程序中创建了一个子目录,例如 data ,以显示在下拉菜单中。我使用以下代码,但我不能访问数据子目录中的文件。



在ui .r:

  filenames<  -  list.files(pattern =\\.csv)
selectInput(inputId =dataset,label =选择平台注释文件,文件名)

r:

  dataInput<  -  reactive({
if(grepl([/ \\\ \],输入$ dataset)){
stop(Invalid dataset)
}
read.csv(file.path(data,input $ dataset))
})

output $ annotation< - renderDataTable({
withProgress(message ='正在加载数据...',{
dataInput()

})
})

上述代码允许我访问csv文件如果他们在应用程序内,因为我的 server.r ui.r 是, app。



我也想知道这是正确的方式访问上述代码的数据,因为我不能在我的下面的代码访问数据。 p>

  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),]
}

我也试过了。

  filenames<  -  list.files(pattern =\\.csv $ data)##数据是我的文件夹里面闪亮的应用程序。 

以访问闪亮应用程序中的数据子目录用csv文件,但不能做。



已编辑:输入文件示例

  ID基因标题基因符号
1007_s_at盘状结构域受体酪氨酸激酶1 DDR1
1053_at复制因子C(激活剂1)2,40kDa 7-mar
117_at热休克70kDa蛋白6(HSP70B')HSPA6
121_at盒8 PAX8
1255_g_at鸟苷酸环化酶激活剂1A(视网膜)GUCA1A
1294_at泛素样修饰激活酶7 UBA7
1320_at蛋白酪氨酸磷酸酶,非受体PTPN21
1405_i_at趋化因子基序)配体5 CCL5 / CCL6
1431_at
1438_at EPH受体B3 EPHB3
1487_at雌激素相关受体αESRRA
1494_f_at细胞色素P450,家族2 CYP2A6 / CYP2

解决方案

当您调用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆