- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 visNetwork 制作一个 Shiny 的交互式网络/思维导图应用程序。 visNetwork 允许交互式创建和操作网络图,如何将这些结果保存在 R data.frame 中?
我查看了文档,但无法理解如何提取更改。
下面是 Shiny 的应用程序的代码。
ui <- navbarPage(
# Application title
"Old Faithful Geyser Data",
tabPanel("Plot"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
mainPanel(
visNetworkOutput("network")
)
)
)
server <- function(input, output) {
output$network <- renderVisNetwork({
nodes <- data.frame(id = 1,
label = 1)
edges <- data.frame(from = as.numeric(),
to = as.numeric())
visNetwork(nodes, edges) %>%
visEdges(arrows = "to") %>%
visHierarchicalLayout(direction = "RL", levelSeparation = 500) %>%
visOptions(manipulation = TRUE)
observe({
visNetworkProxy("network_proxy_nodes") %>%
visUpdateNodes(nodes = input$mynetwork__graphChange)
})
})
}
nodes <- data.frame(id = c(1:2),
label = c(1:2))
edges <- data.frame(from = 1,
to = 2)
最佳答案
input$[my network name]_graphChange
manipulation
创建的元素option 返回一个列表,描述用户刚刚更改的内容。我们可以使用该信息来更新节点和边的主要数据帧。
此代码显示一个用户可以编辑的图形,以及两个显示图形中当前所有节点和边的表,包括用户的更改。 ( This answer 提供了有关如何使用 reactiveValues
存储动态更新的数据框的有用指导。)
require(shiny)
require(visNetwork)
library(dplyr)
# Initialize the graph with these nodes/edges. We have to assign edges an ID
# in case the user edits them later.
init.nodes.df = data.frame(id = c("foo", "bar"),
label = c("Foo", "Bar"),
stringsAsFactors = F)
init.edges.df = data.frame(id = "foobar",
from = "foo",
to = "bar",
stringsAsFactors = F)
ui <- fluidPage(
fluidRow(
# Display two tables: one with the nodes, one with the edges.
column(
width = 6,
tags$h1("Nodes in the graph:"),
tableOutput("all_nodes"),
tags$h1("Edges in the graph:"),
tableOutput("all_edges")
),
# The graph.
column(
width = 6,
visNetworkOutput("editable_network", height = "400px")
)
)
)
server <- function(input, output) {
# `graph_data` is a list of two data frames: one of nodes, one of edges.
graph_data = reactiveValues(
nodes = init.nodes.df,
edges = init.edges.df
)
# Render the graph.
output$editable_network <- renderVisNetwork({
visNetwork(graph_data$nodes, graph_data$edges) %>%
visOptions(manipulation = T)
})
# If the user edits the graph, this shows up in
# `input$[name_of_the_graph_output]_graphChange`. This is a list whose
# members depend on whether the user added a node or an edge. The "cmd"
# element tells us what the user did.
observeEvent(input$editable_network_graphChange, {
# If the user added a node, add it to the data frame of nodes.
if(input$editable_network_graphChange$cmd == "addNode") {
temp = bind_rows(
graph_data$nodes,
data.frame(id = input$editable_network_graphChange$id,
label = input$editable_network_graphChange$label,
stringsAsFactors = F)
)
graph_data$nodes = temp
}
# If the user added an edge, add it to the data frame of edges.
else if(input$editable_network_graphChange$cmd == "addEdge") {
temp = bind_rows(
graph_data$edges,
data.frame(id = input$editable_network_graphChange$id,
from = input$editable_network_graphChange$from,
to = input$editable_network_graphChange$to,
stringsAsFactors = F)
)
graph_data$edges = temp
}
# If the user edited a node, update that record.
else if(input$editable_network_graphChange$cmd == "editNode") {
temp = graph_data$nodes
temp$label[temp$id == input$editable_network_graphChange$id] = input$editable_network_graphChange$label
graph_data$nodes = temp
}
# If the user edited an edge, update that record.
else if(input$editable_network_graphChange$cmd == "editEdge") {
temp = graph_data$edges
temp$from[temp$id == input$editable_network_graphChange$id] = input$editable_network_graphChange$from
temp$to[temp$id == input$editable_network_graphChange$id] = input$editable_network_graphChange$to
graph_data$edges = temp
}
# If the user deleted something, remove those records.
else if(input$editable_network_graphChange$cmd == "deleteElements") {
for(node.id in input$editable_network_graphChange$nodes) {
temp = graph_data$nodes
temp = temp[temp$id != node.id,]
graph_data$nodes = temp
}
for(edge.id in input$editable_network_graphChange$edges) {
temp = graph_data$edges
temp = temp[temp$id != edge.id,]
graph_data$edges = temp
}
}
})
# Render the table showing all the nodes in the graph.
output$all_nodes = renderTable({
graph_data$nodes
})
# Render the table showing all the edges in the graph.
output$all_edges = renderTable({
graph_data$edges
})
}
shinyApp(ui = ui, server = server)
关于r - 如何在 Shiny 中提取和保存 visNetwork 操作更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54846529/
关于将igraph与visNetwork结合,我有一个非常简单的问题。我想用visEdges(value = E(graph)$ weight)加权边缘,但这不起作用。 这是一个说明问题的玩具示例:
这个问题已经有答案了: newline in [duplicate] (9 个回答) 已关闭 6 年前。 在 R 中,如何在 visNetwork 中拥有多行标题? \n似乎没有解决方案: requ
这个问题已经有答案了: newline in [duplicate] (9 个回答) 已关闭 6 年前。 在 R 中,如何在 visNetwork 中拥有多行标题? \n似乎没有解决方案: requ
引用我之前的一篇文章,其中包含完整的可重现代码:VisNetwork from IGraph - Can't Implement Cluster Colors to Vertices 我的目标是更改
我已经使用 Shiny 中的 visNetwork 包构建了我的网络。我想单击一个节点,然后从数据框中显示有关该节点的信息。我已经能够使用单击和近点函数对散点图执行此操作,例如此处显示的 Shiny
我正在尝试使用 visNetwork 包可视化我的网络。但我发现自己对控制节点大小和边宽完全感到困惑。在第一个示例中,我在节点中设置了 value=1,在边缘中设置了 value=0.1。在第二个示例
我想使用 visNetwork 包绘制网络。我希望我的节点在所有不同的网络中对相同的组使用相同的颜色。所以我要 A组->蓝色 B组->黄色 C 组 -> 红色。 这是前 3 个默认颜色。这是第一个简单
我有使用“igraph”库制作的网络图: library(tidyverse) library(igraph) set.seed(123) n=15 data = data.frame(tibble(
我想并排放置两个 visNetwork 图以进行视觉比较。使用带有 par() 或 layout() 的 igraph 可以进行多图定位。有没有办法为 visNetwork 做到这一点?解决方法/问题
我找到了一种将 igraph 转换为 visNetwork 的方法(请参阅 Interactive arules with arulesViz and visNetwork )。假设从 igraph
我一直有这个问题。我只能在一张图中获得一个或另一个但不能同时获得两个选项。下面是代码,我从@lukeA 那里得到了很多帮助,让我走到了这一步。 我有下图,我可以在其中将簇颜色输入 visNetwork
我正在尝试在 visNetwork 节点中嵌入一个操作按钮,以便可以通过单击工具提示中的按钮来启动操作。 我可以让按钮出现在节点标签中,但单击它时不会触发任何事件。我哪里出错了? 最小示例: libr
这是一个更普遍的问题:VisNetwork from IGraph - Can't Implement Cluster Colors to Vertices 我有一个 igraph,已转换为 visN
我开始使用名为 visNetwork 的软件包,我觉得它在未来的用户界面使用方面有很大的潜力。 尽管如此,我还是遇到了一些麻烦。我创建了一个 igraph,并应用了聚类算法,特别是 fastgreed
我正在查看美国参议员的 Twitter 网络。我希望能够选择一个参议员(使用 nodeIdSelection)并仅突出显示连接到该选定 Node 的 Node 并仅突出显示这些连接的边缘(这是我无法弄
我使用了此 question 中给出的示例但我想调整它以显示已选择节点的数据(不是所有节点,但只有这个节点)并且也不使用操作按钮,以便在我单击节点时立即显示数据。 我尝试了很多解决方案都没有成功。 当
我正在尝试使用 visNetwork 制作一个 Shiny 的交互式网络/思维导图应用程序。 visNetwork 允许交互式创建和操作网络图,如何将这些结果保存在 R data.frame 中? 我
我想将节点的位置固定在 (1,0)、(0,1)、(-1,0)、(0,-1) 和 (0,0) 处。然而,它不起作用,我的Java知识为零(看来here是关于Java代码的问题)。 有人可以帮忙吗?这是一
我正在探索 visNetwork,无法弄清楚为什么这个不显示边缘 library(visNetwork) nodes=data.frame(node=c('m1','m2','n1','n2')) a
给定的 visNetwork 脚本创建如下快照中的 visNetwork 图。我的问题是,如果您看到第一个和第二个节点,则两者之间的边缘是弯曲的。有没有一种方法可以在不改变边缘长度的情况下使边缘笔直。
我是一名优秀的程序员,十分优秀!