r - 使 R Shiny 的 renderPlot 对文本输入使用react

标签 r bioinformatics shiny

我正在开发我的第一个 Shiny 应用程序,但在为我的绘图创建输入参数以响应用户在文本输入框中的输入时遇到问题。

这是一个精简的代码示例,对于那些以前使用过shiny的人来说应该很熟悉。

#ui.R
library(shiny)
shinyUI(fluidPage(
  titlePanel("Shiny App"),

  sidebarLayout(
    sidebarPanel(h2("Menu"),

mainPanel(h1("Main"),
tabPanel("Differential Expression",
         column(6,
               p("Input your gene of interest below"),
               textInput(uiOutput("GeneVariable"), label = h4("Gene of interest"),
               value = "Gjb2"),
               submitButton("Submit")),
         plotOutput("plot2"),

    )
  )
))

#server.R
shinyServer(function(input, output) {

 output$plot2 <- renderPlot({
    scde.test.gene.expression.difference("GeneVariable", 
                                         models=o.ifm, counts=cd, prior=o.prior)
  })

GeneVariable <- reactive({ ###I don't know what to put here#####
  })
})

我需要用户能够将基因名称输入到“GeneVariable”位置的文本输入框中,并由 scde.test.gene.express.difference 函数处理名称。

感谢您的帮助和耐心,我是新手。

最佳答案

以下方法解决了这个问题

#ui.R
library(shiny)
shinyUI(fluidPage(
  titlePanel("Shiny App"),

  sidebarLayout(
    sidebarPanel(h2("Menu"),

mainPanel(h1("Main"),
tabPanel("Differential Expression",
         column(6,
               p("Input your gene of interest below"),
               textInput("input$GeneVariable"), label = h4("Gene of interest"),
               value = "Gjb2"),
               submitButton("Submit")),
         plotOutput("plot2"),

    )
  )
))

.

#server.R
shinyServer(function(input, output) {

 output$plot2 <- renderPlot({
    scde.test.gene.expression.difference(input$`input$GeneVariable`, 
                                         models=o.ifm, counts=cd, prior=o.prior)
  })

GeneVariable <- reactive({input$GeneVariable})
  })
})

关键是使用 input$'input$GeneVariable' 将用户的 react 性输入打印到绘图函数中。

关于r - 使 R Shiny 的 renderPlot 对文本输入使用react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42474849/

相关文章:

javascript - 如何在 R Shiny 应用程序中添加 JavaScript 来更改 CSS 文件

r - 我如何添加一个向量来折叠成对中个人的分数?

javascript - 如何根据列中的条件更改数据表行背景颜色,Rshiny

r - 在 R 中使用 plyr 插值数据

python - 如何基于 1000 个符号字符串打印出带有单个替换元素的 1000 个新字符串?

python - 根据同一列表中的下一个项目从列表中删除项目

python - 获取与两个 fastq 文件不同的记录

r - 是否可以将传单 map 传递到另一个模块?

css - Shiny 的应用程序作为功能,在哪里放置 www/文件夹、CSS、JS

r - 对矩阵列表求和