【发布时间】:2018-09-24 13:08:13
【问题描述】:
我有一个简单的闪亮应用程序,它显示一个网络,在下表中,您可以看到所有通过边缘和边缘名称的网络节点连接。我想更新数据表以在单击节点时仅显示选定的节点信息。例如,当我单击节点“articaine”时,表格中只会显示“articaine”连接。
#dataset
id<-c("articaine","benzocaine","etho","esli")
label<-c("articaine","benzocaine","etho","esli")
node<-data.frame(id,label)
from<-c("articaine","articaine","articaine","articaine","articaine","articaine","articaine","articaine","articaine")
to<-c("benzocaine","etho","esli","benzocaine","etho","esli","benzocaine","etho","esli")
title<-c("SCN1A","SCN1A","SCN1A","SCN2A","SCN2A","SCN2A","SCN3A","SCN3A","SCN3A")
edge<-data.frame(from,to,title)
#app
#ui.r
library(igraph)
library(visNetwork)
library(dplyr)
library(shiny)
library(shinythemes)
library(DT)
ui <- fluidPage(theme = shinytheme("cerulean"), # Specify that the Cerulean Shiny theme/template should be used
# Generate Title Panel at the top of the app
titlePanel("Network Visualization App"),
# Render as a sidebarLayout. Shiny expects that a sidebarPanel() function and a mainPanel() function are present.
sidebarLayout(
# Sidebar section. Can set the width of the sidebar for any value ranging from 1 to 12.
sidebarPanel(
), # End of the sidebar panel code
# Define the main panel
mainPanel(
h3("Network Visualization"),
# Plot the network diagram within the main panel.
# Note that visNetworkOutput is not a Shiny package function, but a visNetwork package function.
visNetworkOutput("plot2"),
fluidRow(
DTOutput('tbl')
)
) # End of main panel code
)
)
#server.r
library(igraph)
library(visNetwork)
library(dplyr)
library(shiny)
library(shinythemes)
server <- function (input, output, session){
# Use the renderVisNetwork() function to render the network data.
output$plot2 <- renderVisNetwork({
visNetwork(nodes = node,edge)%>%
visOptions(highlightNearest=T, nodesIdSelection = T) %>%
# Specify that hover interaction and on-screen button navigations are active
visInteraction(hover = T, navigationButtons = T) %>%
visIgraphLayout()
})
output$tbl = renderDT(
edge, options = list(lengthChange = FALSE)
)
}
【问题讨论】:
-
看起来
visGetSelectedNodes()应该允许您将选定的节点传递给server并限制您的数据表。 -
有用的评论。如果我能精确地创建我想要的表而不仅仅是节点