-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiny_igraph.R
75 lines (53 loc) · 1.85 KB
/
shiny_igraph.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#### Load necessary packages and data ####
library(shiny)
library(networkD3)
library(igraph)
df <- read.csv("dataframe.csv", header=TRUE)
namesdf <- read.csv("unique_names.csv", header=TRUE)
names <- c("ALL", levels(unlist(namesdf$id)))
# ------------------------- Server --------------------------------#
server <- function(session, input, output) {
output$domains <- renderUI({ selectInput(
inputId = "domain",
label = "Select domain",
choices = names,
selected = "ALL")})
newData <- reactive({
# Filter the dataset by the chosen value
datadata <- df
#print(input$domain)
if (!is.null(input$domain)) {
if (input$domain != "ALL"){
isolate({
datadata <- subset(datadata, from %in% input$domain |
to %in% input$domain)
})
}
}
return(datadata)
})
output$network <- renderSimpleNetwork({
simpleNetwork(newData(), Source = "from", Target = "to",
zoom = T, fontSize = 17,
linkDistance = 150, charge = -250,
height = 700, width = 500)
})
#output$table <- renderDataTable(newData())
}
# ---------------------------- UI ----------------------------------#
ui <- shinyUI(fluidPage(
titlePanel("SDTM Datasets in Shiny networkD3"),
sidebarLayout(
sidebarPanel(
uiOutput(outputId="domains"),
#h5("Used datasets:"),
#dataTableOutput('table')
# "save as csv" button to get a list of all datasets used to create another one
),
mainPanel(
simpleNetworkOutput("network", height = "800px")
)
)
))
# ----------------------------- RUN --------------------------------#
shinyApp(ui = ui, server = server)