如何将ShinyR功能与UI集成?

问题描述 投票:0回答:2

我正在尝试开发我的第一个小型shinyR应用程序,但它的UI不能与其功能正确集成。在运行app后浏览文件时,不执行该功能。请在下面找到我的代码。我是这个领域的新人,我将非常感谢你的支持。

library(seqinr)
library(shiny)
# User interface
ui <- fluidPage(
  titlePanel("Welcome to DotMatcher Plot App"),
  sidebarLayout(
    sidebarPanel (
      fileInput("protein1",
                label = "Choose a file",
                multiple = FALSE,
                accept =c("text", "fasta")),
      fileInput( "protein2",
                 label = NULL,
                 multiple=FALSE,
                 accept =c("text", "fasta"))
    ),
    # Outputs
    mainPanel(
      plotOutput(outputId = "plot")
    )
  )
)
)
# Server Function
server <- function(input, output) {
  movies_subset1 <- reactive({
    req(input$protein1)})
  movies_subset2 <- reactive({
    req(input$protein2)
  })
  gl<-pairwiseAlignment(pattern = movies_subset1, subject = movies_subset2)
  output$plot <- renderPlot({
    print (gl)

    })

}
# App 
shinyApp(ui = ui, server = server)
r shiny bioinformatics
2个回答
0
投票

无论何时使用反应式表达式,都必须使用括号来获取该表达式的值。我添加了一个打印声明,以便您可以看到差异。代码现在应该可以工作了。但总的来说,由于你不操纵你的输入,所以没有必要包装而不是反应式表达式。

library(seqinr)
    library(shiny)
    # User interface
    ui <- fluidPage(
        titlePanel("Welcome to DotMatcher Plot App"),
        sidebarLayout(
            sidebarPanel (
                fileInput("protein1",
                          label = "Choose a file",
                          multiple = FALSE,
                          accept =c("text", "fasta")),
                fileInput( "protein2",
                           label = NULL,
                           multiple=FALSE,
                           accept =c("text", "fasta"))
            ),
            # Outputs
            mainPanel(
                plotOutput(outputId = "plot")
            )
        )
    )

    # Server Function
    server <- function(input, output) {
        seq1 <- reactive({
            req(input$protein1)})
        seq2 <- reactive({
            req(input$protein2)
        })

        output$plot <- renderPlot({

    print(seq1)
    print(seq1())

            dotPlot(seq1(), seq2(), wsize = 100, wstep = 100, nmatch = 100)

        })

    }
    # App 
    shinyApp(ui = ui, server = server)

0
投票

以下预处理确实对我有用,但现在我在输出功能中面临问题

library(seqinr)
library(shiny)
# User interface
ui <- fluidPage(
  titlePanel("Welcome to DotMatcher Plot App"),
  sidebarLayout(
    sidebarPanel (
      fileInput("protein1",
                label = "Choose a file",
                multiple = FALSE,
                accept =c("text", "fasta")),
      fileInput( "protein2",
                 label = NULL,
                 multiple=FALSE,
                 accept =c("text", "fasta"))
    ),
    # Outputs
    mainPanel(
      plotOutput(outputId = "plot")
    )
  )
)

# Server Function
server <- function(input, output) {
  seq1 <- reactive({
    req(s2c(paste(input$protein1, collapse = "")})
  seq2 <- reactive({
    req(s2c(paste(input$protein2, collapse = "")
  })

  output$plot <- renderPlot({



    dotPlot(seq1(), seq2(), wsize = 100, wstep = 100, nmatch = 100)

  })

}
# App 
shinyApp(ui = ui, server = server)
© www.soinside.com 2019 - 2024. All rights reserved.