|
1 | | -# |
2 | | -# This is a Shiny web application. You can run the application by clicking |
3 | | -# the 'Run App' button above. |
4 | | -# |
5 | | -# Find out more about building applications with Shiny here: |
6 | | -# |
7 | | -# http://shiny.rstudio.com/ |
8 | | -# |
9 | | - |
10 | 1 | library(shiny) |
11 | 2 | library(visNetwork) |
12 | 3 |
|
13 | | -# Define UI for application that draws a histogram |
14 | 4 | ui <- shinyUI(fluidPage( |
15 | | - actionButton("goCol", "Collapsed !"), |
16 | | - actionButton("goUC", "uncollapse!"), |
17 | | - actionButton("goRm", "remove event!"), |
18 | | - actionButton("goAdd", "add event!"), |
19 | | - fluidRow(column(4, div(id = "conf")), |
20 | | - column(8, visNetworkOutput("distPlot"))) |
21 | | - |
22 | | - |
| 5 | + visNetworkOutput("net") |
23 | 6 | )) |
24 | 7 |
|
25 | | -# Define server logic required to draw a histogram |
26 | 8 | server <- shinyServer(function(input, output) { |
27 | | - |
28 | | - output$distPlot <- renderVisNetwork({ |
29 | | - set.seed(125) |
30 | | - nodes <- data.frame(id = 1:15, label = paste("Label", 1:15), |
31 | | - group = sample(LETTERS[1:3], 15, replace = TRUE)) |
32 | | - |
33 | | - edges <- data.frame(from = trunc(runif(15)*(15-1))+1, |
34 | | - to = trunc(runif(15)*(15-1))+1) |
35 | | - |
36 | | - visNetwork(nodes, edges) %>% visOptions(highlightNearest = T, collapse = T) %>% |
37 | | - visEdges(arrows = "to") %>% visConfigure(container = "conf") |
38 | | - |
39 | | - }) |
40 | | - |
41 | | - observe({ |
42 | | - if(input$goCol > 0){ |
43 | | - visNetworkProxy("distPlot") %>% |
44 | | - visCollapse(nodes = c(10,3), clusterOptions = list( shape ="square", label = "and so ?"), |
45 | | - labelSuffix = "Cool") |
46 | | - } |
47 | | - }) |
48 | | - |
49 | | - observe({ |
50 | | - if(input$goUC > 0){ |
51 | | - visNetworkProxy("distPlot") %>% visUncollapse(keepCoord = TRUE) |
52 | | - } |
53 | | - }) |
54 | | - |
55 | | - observe({ |
56 | | - if(input$goRm > 0){ |
57 | | - visNetworkProxy("distPlot") %>% visEvents(type = "off", doubleClick = "networkOpenCluster") |
58 | | - } |
59 | | - }) |
60 | | - |
61 | | - observe({ |
62 | | - if(input$goAdd > 0){ |
63 | | - visNetworkProxy("distPlot") %>% visEvents(type = "on", doubleClick = "networkOpenCluster") |
64 | | - } |
65 | | - }) |
66 | | - |
| 9 | + |
| 10 | + output$net <- renderVisNetwork({ |
| 11 | + set.seed(125) |
| 12 | + nodes <- data.frame(id = 1:15, label = paste("Label", 1:15), title = paste("Label", 1:15), |
| 13 | + group = sample(LETTERS[1:3], 15, replace = TRUE)) |
| 14 | + |
| 15 | + edges <- data.frame(from = trunc(runif(15)*(15-1))+1, |
| 16 | + to = trunc(runif(15)*(15-1))+1) |
| 17 | + |
| 18 | + # using your own css |
| 19 | + # visNetwork(nodes, edges) %>% |
| 20 | + # visInteraction(tooltipStyle = "position: fixed;visibility:hidden;text-decoration: underline;") |
| 21 | + |
| 22 | + # default css + text-decoration |
| 23 | + visNetwork(nodes, edges) %>% |
| 24 | + visInteraction(tooltipStyle = "position: fixed;visibility:hidden;padding: 5px;font-family: verdana;font-size:14px; |
| 25 | + font-color:#000000;background-color: #f5f4ed;-moz-border-radius: 3px;-webkit-border-radius: 3px; |
| 26 | + border-radius: 3px;border: 1px solid #808074;box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2); |
| 27 | + max-width:400px;word-break: break-all;text-decoration: underline;") |
| 28 | + |
| 29 | + }) |
67 | 30 | }) |
68 | 31 |
|
69 | 32 | # Run the application |
|
0 commit comments