首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >brushPoints RShiny - dsplay从系统发育树中选择的提示

brushPoints RShiny - dsplay从系统发育树中选择的提示
EN

Stack Overflow用户
提问于 2020-01-23 16:06:53
回答 1查看 228关注 0票数 0

我想通过RShiny上传一个系统进化树,并使用brushPoints函数允许用户选择系统发育树的提示。最终,选择的提示将被用作通过注释更新树的信息。我的想法是显示选择的提示,以确认选择,但我无法生成verbatiumTextOutput。建议

以下是我的尝试:

代码语言:javascript
复制
library(shiny)
library(ggplot2)
library(treeio)
library(ggtree)
library(tidytree) 

tree <- treeio::read.newick("1509MLJF6-1.dnd")

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Select Individuals and Display Data"),

  # Show a plot and output table 
  mainPanel(
    plotOutput("treeDisplay", brush = "plot_brush"),
    verbatimTextOutput("selectedIndivs")

  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  output$treeDisplay <- renderPlot({
    ggplot(tree) + geom_tree() + geom_tiplab()
  })

  output$selectedIndivs <- renderPrint({
    brushedPoints(tree, input$plot_brush)
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

运行应用程序时,错误为:警告:[:不正确的维度数中的错误“

在选择个体时,错误是:rep中的错误:无效的‘时间’参数

如果需要,系统发育树位于这里

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-24 16:39:00

ape方法

要让用户浏览这些提示,您需要知道地块上内部节点和终端节点的x和y坐标。您可以使用ape包获得这些信息。然后,一旦得到了刷过的区域的坐标,就可以将phylo坐标表子集为只刷过的部分。在下面的示例中,我们必须显式地告诉brushedPoints在哪里查找xy坐标(数据帧中的xvaryvar列)。根据树上物种的数量,您可能需要扩展绘图区域以避免重叠,这样就可以轻松地将物种刷过。

代码:

代码语言:javascript
复制
library(shiny)
library(ape)

Tree <- rtree(n=20)
Tree <- ladderize(Tree)

ui <- basicPage(
  plotOutput("plot1", brush = "plot_brush"),
  tableOutput("brushed_subtree")
)

server <- function(input, output) {

  output$plot1 <- renderPlot({
    plot(Tree)
  })

  getTreeInfo <- reactive({
    plot(Tree)
    plotinfo <- get("last_plot.phylo", envir = .PlotPhyloEnv)
    tips_xy <- data.frame(Tip=Tree$tip.label, 
                          xvar=plotinfo$xx[1:Ntip(Tree)], 
                          yvar=plotinfo$yy[1:Ntip(Tree)])
    return(tips_xy)
  })

  # render selected tips table 
  output$brushed_subtree <- renderTable({
    brushedPoints(getTreeInfo(), input$plot_brush, xvar = "xvar", yvar = "yvar")
  })

}

shinyApp(ui, server)

全球综合框架:

ggtree方法

ggtree方法更容易实现。实际上,您已经接近了,除了将树传递给brushedPoints之外,您还需要提供ggtree绘图的$data组件。请注意,在这种情况下,刷过的区域必须包括想要的尖端的终端分支,因为图的坐标是由边缘数据帧给出的,并且提示是相对于先前绘制的(终端)边缘绘制的单独的geom。

代码

代码语言:javascript
复制
library(shiny)
library(ggplot2)
library(treeio)
library(ggtree)
library(tidytree) 

tree <- treeio::read.newick("1509MLJF6-1.dnd")
treedt <- as.treedata(tree)

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Select Individuals and Display Data"),

  # Show a plot and output table 
  mainPanel(
    plotOutput("treeDisplay", brush = "plot_brush"),
    verbatimTextOutput("selectedIndivs")

  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

  make_tree <- reactive({
     ggplot(tree) + geom_tree() + geom_tiplab()
  })

  output$treeDisplay <- renderPlot({
    make_tree()
  })

  output$selectedIndivs <- renderPrint({
    brushedPoints(make_tree()$data, input$plot_brush)
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

全球综合框架:

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59882706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档