我已经用VisNetwork和闪亮构建了一个网络图。我对结果非常满意。我想做的是使用搜索栏(例如:demo/)搜索数据中的节点。
我用的是闪光板。所以我试着用"sidebarSearchForm“。然而,当我运行该应用程序并尝试使用搜索表单时,将不会返回任何内容。
下面是我的ui代码:
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这是服务器的代码;
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发布于 2016-10-13 21:11:32
例如,您可以使用visNetworkProxy和visSelectNodes来完成这一任务,比如使用一个简单的grepl:
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)发布于 2016-10-13 15:43:04
你查过这个吗?
http://datastorm-open.github.io/visNetwork/shiny.html
检查visNetworkProxy部分。
此外,演示代码附带的包有您想要实现的东西。
发布于 2022-02-06 14:12:43
可以将bthieurmel的上述代码修改为下面的代码,以启用不区分大小写的搜索:
current_node <- nodes[grep(input$searchText, nodes$label, ignore.case = T), "id"]https://stackoverflow.com/questions/40024937
复制相似问题