首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪亮的VisNetwork图搜索栏

闪亮的VisNetwork图搜索栏
EN

Stack Overflow用户
提问于 2016-10-13 15:18:30
回答 3查看 1.7K关注 0票数 2

我已经用VisNetwork和闪亮构建了一个网络图。我对结果非常满意。我想做的是使用搜索栏(例如:demo/)搜索数据中的节点。

我用的是闪光板。所以我试着用"sidebarSearchForm“。然而,当我运行该应用程序并尝试使用搜索表单时,将不会返回任何内容。

下面是我的ui代码:

代码语言:javascript
复制
ui <- dashboardPage(skin = "black",
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Network", tabName = "network", icon = icon("dashboard")),
      sidebarSearchForm(textId = "searchText", buttonId = "searchButton", label = "Search...")
   )
  ),
  dashboardBody(
    box(
      title = "Network",  status = "warning", solidHeader = TRUE, collapsible = TRUE,
      visNetworkOutput("network_proxy", height = 700)  
    )
  )
)#end ui

这是服务器的代码;

代码语言:javascript
复制
server <- function(input, output) {
  output$network_proxy <- renderVisNetwork({
    visNetwork(my.nodes, my.edges, height = "100%")
  })
  output$searchString <- renderText({
    if (input$searchButton == 0)
      return()
    isolate({input$searchString})
  })
} #end server
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-10-13 21:11:32

例如,您可以使用visNetworkProxyvisSelectNodes来完成这一任务,比如使用一个简单的grepl

代码语言:javascript
复制
nodes <- data.frame(id = 1:3, label = c("A", "B", "A"))
edges <- data.frame(from = c(1,2), to = c(1,3))

require(visNetwork)
require(shiny)
require(shinydashboard)
ui <- dashboardPage(skin = "black",
                    dashboardHeader(),
                    dashboardSidebar(
                      sidebarMenu(
                        menuItem("Network", tabName = "network", icon = icon("dashboard")),
                        sidebarSearchForm(textId = "searchText", buttonId = "searchButton", label = "Search...")
                      )
                    ),
                    dashboardBody(
                      box(
                        title = "Network",  status = "warning", solidHeader = TRUE, collapsible = TRUE,
                        visNetworkOutput("network_proxy", height = 700)
                      )
                    )
)


server <- function(input, output, session) {
  output$network_proxy <- renderVisNetwork({
    visNetwork(nodes, edges, height = "100%")
  })

  observe({
    if(input$searchButton > 0){
      isolate({
        print(input$searchText)
        current_node <- nodes[grep(input$searchText, nodes$label), "id"]
        print(current_node)
        visNetworkProxy("network_proxy") %>% visSelectNodes(id  = current_node)
      })
    }
  })

} #end server

shiny::shinyApp(ui, server)
票数 3
EN

Stack Overflow用户

发布于 2016-10-13 15:43:04

你查过这个吗?

http://datastorm-open.github.io/visNetwork/shiny.html

检查visNetworkProxy部分。

此外,演示代码附带的包有您想要实现的东西。

票数 0
EN

Stack Overflow用户

发布于 2022-02-06 14:12:43

可以将bthieurmel的上述代码修改为下面的代码,以启用不区分大小写的搜索:

代码语言:javascript
复制
current_node <- nodes[grep(input$searchText, nodes$label, ignore.case = T), "id"]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40024937

复制
相关文章

相似问题

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