【问题标题】:How to make a selectInput with a choice list following an inputdata如何在输入数据之后使用选择列表制作 selectInput
【发布时间】: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 等。

任何帮助将不胜感激。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    与documentation 中的示例一样,将NULL 检查添加到input$file2 的阅读器逻辑。

    当应用程序启动时,输入有一个默认的NULL 值,直到第一次设置它。所以你最初给read.csv 一个NULL 引用来读取。

    【讨论】:

    • 好吧,这些事情总是需要一些时间才能弄清楚。
    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多