R网络图在闪亮不起作用

时间:2018-05-07 02:50:37

标签: r shiny igraph

我正在尝试根据用户的下拉输入显示不同的图表。我有其他输入工作。只是网络图不起作用。如果我将它切换到另一个图表,它的工作原理;它只是网络图不起作用。

    if(input$level == "function"){

  data = matrix(sample(0:1, 400, replace = TRUE, prob = c(0.8,0.2)), nrow = 20)
  network = graph_from_adjacency_matrix(data, mode='undirected', diag = F)

  plot(network, layout = layout.circle, main = "circle")
}

它都属于反应函数。我也尝试过使用igraph库,以及igraphinshiny库

1 个答案:

答案 0 :(得分:1)

以下示例绘制网络图或根据所选选项的5个点的简单绘图:

library(shiny)
library(igraph)
ui <- fluidPage(

  sidebarLayout(
    sidebarPanel(
      selectInput("graph", 
                  label = "Choose graph to display",
                  choices = c("Simple plot", "Network Graph"), 
                  selected = "Network Graph")), 
    mainPanel(
      plotOutput("myplot")
    )
  )

)

server <- function(input, output) {

  output$myplot <- renderPlot({

    # Plot Network graph is selected
    if (input$graph == "Network Graph"){
      data = matrix(sample(0:1, 400, replace = TRUE, prob = c(0.8,0.2)), nrow = 20)
      network = graph_from_adjacency_matrix(data, mode='undirected', diag = F)

      # plot simple graph of 5 points
      plot(network, layout = layout.circle, main = "circle")
    } else {
      plot(1:5)
    }
  })


}

shinyApp(ui, server)