【发布时间】:2018-08-29 01:22:18
【问题描述】:
我的想法是在用户上传文件时从列中获取所有唯一值,之后我在 selectinput 处的选择将更改为这些唯一值。
有我的ui.R代码:
`library(shinythemes)
shinyUI(fluidPage(theme = "mystyle.css",
titlePanel("Pruebas"),
sidebarLayout(
sidebarPanel(
fileInput("file2", HTML("<table><tr><td><strong>Choose your VCF file</strong></td>
<td>
<div class='help-tip'>
<p>Upload your VCF file with which you will work.</p>
</div></td></tr>
</table>
"),
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".vcf")),
selectInput("filter", h3("Choose your filter"),
choices = list("Chr 1" = 1, "Chr 2" = 2,
"Chr 3" = 3),selected = 1)`
所以我的想法是用“file2”做一个过滤器并使用它来获取那些唯一值:
`df <- read.csv(input$file2$datapath, header = TRUE, sep = "\t", quote = '"', skip = 56)
x <- unique(df[,1]
x <- levels(x)`
然后如果我们执行 x[1],我们将获得第一个唯一元素,然后我想创建一个选择列表,其中选项是列表“x”上的所有元素。
我在 server.R 上尝试了一些东西:
` outVar <- reactive({
inFile <- input$file2
if (is.null(inFile))
return(NULL)
dff <- read.csv(inFile$datapath, header = TRUE, sep = "\t", quote = '"', skip = 56)
y <- unique(dff[,1])
y <- levels(y)
y
})
observe({
updateSelectInput(session, "mychrlist",
choices = outVar()
)})`
然后在 ui.R:
`selectInput("select2", HTML("<table><tr><td><strong>Chromosome</strong></td>
<td>
<div class='help-tip'>
<p>Filter by chromosome to focus one chromosome insted all of them.</p>
</div></td></tr>
</table>
"),
choices = ("mychrlist")),`
但选择列表保留在“mychrlist”,我想要 Chr0、Chr1、Chr2 等。
任何帮助将不胜感激。
【问题讨论】: