如何将ShinyR功能与UI集成?

时间:2019-04-27 19:45:32

标签: r shiny bioinformatics

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

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)

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:0)

以下预处理确实对我有用,但是现在我在输出函数中遇到了问题

#include <QtWidgets>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsScene *scene = new QGraphicsScene;
    QGraphicsView *view = new QGraphicsView{scene};
    scene->addRect(QRectF(0, 0, 100, 100), QPen(Qt::red), QBrush(Qt::blue));
    scene->addEllipse(QRectF(40, 30, 100, 100), QPen(Qt::green), QBrush(Qt::gray));
    QComboBox *combo_formats = new QComboBox;
    for(const QByteArray & format : QImageWriter::supportedImageFormats()){
        combo_formats->addItem(format);
    }
    QPushButton *save_button = new QPushButton{"Save"};
    QObject::connect(save_button, &QPushButton::clicked,[view, combo_formats](){
       QPixmap pixmap = view->grab();
       QString filename = QString("%1.%2").arg("image").arg(combo_formats->currentText());
       pixmap.save(filename);
    });
    QMainWindow w;
    QWidget *central_widget = new QWidget;
    w.setCentralWidget(central_widget);
    QFormLayout *lay = new QFormLayout{central_widget};
    lay->addRow(view);
    lay->addRow("Select Format:", combo_formats);
    lay->addRow(save_button);
    w.show();
    return a.exec();
}