我正在开发我的第一个 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/