简体   繁体   English

在 R shiny 中使用猿 package 创建 phylog.netic 可视化

[英]Create phylogenetic visualisation using ape package in R shiny

I am creating a shiny web application to take newick input files from the user and then visualise the trees on the screen.我正在创建一个 shiny web 应用程序以从用户那里获取 newick 输入文件,然后在屏幕上可视化树。 I am trying to use the ape package to do this however I am getting stuck writing the server function in my shiny app.我正在尝试使用 ape package 来执行此操作,但是我在我的 shiny 应用程序中编写服务器 function 时遇到了困难。 Would anyone be able to adjust my server function to be able to achieve the visualisation while also having some logic to detect the type of file that is being uploaded as well?谁能调整我的服务器 function 以实现可视化,同时也有一些逻辑来检测正在上传的文件类型?

I have tried the following:我尝试了以下方法:

library(shiny)
library(ape)

ui <- navbarPage("Visualisation Toolbox", 
                 tabPanel("Phylogenic Trees",
                          fluidRow(
                            class = "inputs",
                            column(6, align = "center",
                                   h4("Select File Type:"),
                                   selectInput(inputId = "file_type", "", 
                                               choices = list("Newick" = "newick", 
                                                              "NEXUS" = "nexus",
                                                              "Phylip" = "phylip",
                                                              "RAxML" = "raxml"),
                                               selected = "newick")
                            ),
                            
                            column(6, align = "center",
                                   h4("Select Tree File:"),
                                   fileInput(inputId = "tree_file", "",
                                             buttonLabel = "Browse")
                            ), 
                            plotOutput('contents'),
                            )
                 ),
                 )

server <- function(input, output, session) {
  myPlot = reactiveVal()
  myData = reactive({
    input$tree_file
    myPlot(ape::read.tree(data))
    data
  })
  
  output$contents = renderPlot({
    myPlot()
  })
  }

shinyApp(ui = ui, server = server)

I don't understand fully what you mean by having some logic to detect file type.我不完全理解你所说的有一些逻辑来检测文件类型是什么意思。 However the following example achieves visualization and plots conditionally on input$file_type .但是,以下示例实现了可视化并有条件地绘制input$file_type It may serve as a starting point.它可以作为一个起点。

library(shiny)
library(ape)
ui <- navbarPage("Visualisation Toolbox", 
                 tabPanel("Phylogenic Trees",
                          fluidRow(
                            class = "inputs",
                            column(6, align = "center",
                                   h4("Select File Type:"),
                                   selectInput(inputId = "file_type", "", 
                                               choices = list("Newick" = "newick", 
                                                              "NEXUS" = "nexus",
                                                              "Phylip" = "phylip",
                                                              "RAxML" = "raxml"),
                                               selected = "newick")
                            ),
                            column(6, align = "center",
                                   h4("Select Tree File:"),
                                   fileInput(inputId = "tree_file", "",
                                             buttonLabel = "Browse")
                            ), 
                            plotOutput(outputId  = 'contents'),
                            )
                 ),
                 )

server <- function(input, output, session) {
    output$contents <- renderPlot({
        file <- input$tree_file
        if (is.character(file$datapath)) {
            if (input$file_type %in% c("newick")) 
                plot(ape::read.tree(file$datapath))
        }})
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM