我正在尝试使用networkD3
和闪亮来可视化一些数据。我希望在单击图表中的节点时执行操作。我正在使用diagonalNetwork
函数,如下面的代码所示。
forceNetwork
函数可以选择在单击节点时使clickaction
响应。但是,我找不到diagonalNetwork
函数的类似选项。还有其他方法可以实现吗?
#### Load necessary packages and data ####
library(shiny)
library(networkD3)
data(MisLinks)
data(MisNodes)
hc <- hclust(dist(USArrests), "ave")
URL <- paste0(
"https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata//flare.json")
## Convert to list format
Flare <- jsonlite::fromJSON(URL, simplifyDataFrame = FALSE)
#### Server ####
server <- function(input, output) {
output$simple <- renderDiagonalNetwork({
diagonalNetwork(List = Flare, fontSize = 10, opacity = 0.9)
})
output$force <- renderForceNetwork({
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = input$opacity)
})
##
#dendroNetwork(hc, height = 600)
#
# dendroNetwork(hc, height = 500, width = 800, fontSize = 10,
# linkColour = "#ccc", nodeColour = "#fff", nodeStroke = "steelblue",
# textColour = "#111", textOpacity = 0.9, textRotate = NULL,
# opacity = 0.9, margins = NULL, linkType = c("elbow", "diagonal"),
# treeOrientation = c("horizontal", "vertical"), zoom = FALSE)
}
#### UI ####
ui <- shinyUI(fluidPage(
titlePanel("Shiny networkD3 "),
sidebarLayout(
sidebarPanel(
sliderInput("opacity", "Opacity (not for Sankey)", 0.6, min = 0.1,
max = 1, step = .1)
),
mainPanel(
tabsetPanel(
tabPanel("Simple Network", diagonalNetworkOutput("simple")),
tabPanel("Force Network", forceNetworkOutput("force"))
)
)
)
))
#### Run ####
shinyApp(ui = ui, server = server)
答案 0 :(得分:6)
您可以使用<card ng-repeat="person in vm.persons | unique: 'PTSNumber'"
name="{{person.Firstname}} {{person.Surname}}" theme="user"
ptsnumber="{{ person.PTSNumber }}"
isUser="{{ true }}"
ng-click="vm.setUser(person.PTSNumber, person.Firstname, person.Surname, $event)"></card>
的{{1}}函数将htmlwidgets
事件附加到此类节点...
onRender