在强制网络图中选择多个节点并显示名称r Shiny

时间:2018-09-28 09:05:51

标签: r shiny

我在r Shiny(library(networkD3))中有一个力图,当我选择一个节点以及选择多个节点以便在进一步分析中使用选定的节点时,我想存储一个节点的名称吗? / p>

1。这是闪亮的服务器内部的强制网络功能:

library(shiny)
library(networkD3)
library(DT)
library(SPARQL)
library(collapsibleTree)
library(dplyr)

endpoint <- 'http://statistics.gov.scot/sparql'

query <- 'PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/concept#>
PREFIX data: <http://statistics.gov.scot/data/>
PREFIX sdmxd: <http://purl.org/linked-data/sdmx/2009/dimension#>
PREFIX mp: <http://statistics.gov.scot/def/measure-properties/>
PREFIX stat: <http://statistics.data.gov.uk/def/statistical-entity#>
SELECT ?areaname ?nratio ?yearname ?areatypename WHERE {
?indicator qb:dataSet data:alcohol-related-discharge ;
             sdmxd:refArea ?area ;
             sdmxd:refPeriod ?year ;
             mp:ratio ?nratio .
?year rdfs:label ?yearname .

?area stat:code ?areatype ;
      rdfs:label ?areaname .
?areatype rdfs:label ?areatypename .
}'

# reject bad inputs
#if(!is.data.frame(df)) stop("df must be a data frame")



shinyServer(function(input, output, session) {
  abc <- reactive({
    abc <- input$endpoint    
  }) 
  output$endpoint  <- renderText({ 
    endpoint
  })
  output$query <- renderText({ 
    query
  }) 

  qd <- SPARQL::SPARQL(url=endpoint, query=query)$results
  summary(qd)
  newdata <- qd[1:100,]

  # Create fake data
  src <- c("dataset")
  target <- c(colnames(qd))
  networkData <- data.frame(src, target,stringsAsFactors = FALSE)


  output$summary <- renderPrint({
    summary(qd)
  })

  output$str <- renderPrint({
    str(qd)
  })



  output$force <- renderForceNetwork({
    # make a nodes data frame out of all unique nodes in networkData
    nodes <- data.frame(name = unique(c(networkData$src, networkData$target)))
    # make a group , value = "http://statistics.gov.scot/sparql"variable where nodes in networkData$src are identified
    nodes$group <- nodes$name %in% networkData$src
    # make a links data frame using the indexes (0-based) of nodes in 'nodes'
    links <- data.frame(source = match(networkData$src, nodes$name) - 1,
                        target = match(networkData$target, nodes$name) - 1)


    fn<-forceNetwork(Links = links, Nodes = nodes, Source = "source",
                     Target = "target", NodeID ="name", Group = "group",
                     opacity = input$opacity, opacityNoHover = 1, fontSize = 7,
                     fontFamily = "serif", linkDistance = 300,zoom = TRUE)

    fn$x$nodes$hyperlink <- paste0(
      'https://www.facebook.com/search/top/?q=',
      nodes$name
    )

    #   we can define a click action to open the hyperlink for each node in a new window
    fn$x$options$clickAction = 'window.open(d.hyperlink)'
    fn
  })

目标是:

  • 首先,描述数据集属性(参见图片
  • 在图形中的select属性上显示用于进一步分析的名称(也许将名称存储在变量中)
  • 选择多个节点并仅使用所选节点进行一些分析的可能性

0 个答案:

没有答案