【问题标题】:Using linked brushing with a network graph from ggraph in a Shiny app在 Shiny 应用程序中使用来自 ggraph 的网络图的链接刷牙
【发布时间】:2017-09-26 00:44:33
【问题描述】:

我有一个闪亮的应用程序,其中我有一个使用ggraph 呈现的网络图,类似于下面的应用程序:

library(ggraph)
library(igraph)
library(shiny)

ui <- fluidPage(
    plotOutput("plot", brush = brushOpts(id = "plot_brush"))
)

server <- function(input, output) {
  graph <- graph_from_data_frame(highschool)

  output$plot <- renderPlot({
    ggraph(graph) + 
      geom_edge_link(aes(colour = factor(year))) + 
      geom_node_point()
  })

  observe(print(
    brushedPoints(as_data_frame(graph, what = "vertices"), input$plot_brush)
        )
    )
}

shinyApp(ui, server)

我想做的是,当您在图表中单击并拖动以捕获某些节点时,我可以检查有关捕获的那些特定点的更多信息。目前,我只使用observe({print()}),以便在控制台中查看捕获的内容。

我的问题,每当我在应用程序中选择一个区域时,无论选择的区域中包含多少个节点,控制台都会返回 0 行。如何让它返回所选区域中包含的节点?

【问题讨论】:

    标签: r shiny igraph ggraph


    【解决方案1】:

    This response 给我指路了:

    library(ggraph)
    library(igraph)
    library(shiny)
    library(dplyr)
    
    ui <- fluidPage(
      plotOutput("plot", brush = brushOpts(id = "plot_brush"))
    )
    
    server <- function(input, output) {
      graph2 <- graph_from_data_frame(highschool)
    
      set.seed(2017)
      p <- ggraph(graph2, layout = "nicely") + 
        geom_edge_link() + 
        geom_node_point()
    
      plot_df <- ggplot_build(p)
    
      coords <- plot_df$data[[2]]
    
      output$plot <- renderPlot(p)
    
      coords_filt <- reactive({
        if (is.null(input$plot_brush$xmin)){
          coords
        } else {
        filter(coords, x >= input$plot_brush$xmin, 
               x <= input$plot_brush$xmax, 
               y >= input$plot_brush$ymin, 
               y <= input$plot_brush$ymax)
        }
      })
    
      observe(print(
        coords_filt()
      )
      )
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 2018-07-11
      相关资源
      最近更新 更多