Skip to content

Instantly share code, notes, and snippets.

@SachaEpskamp
Last active September 7, 2017 09:44
Show Gist options
  • Save SachaEpskamp/dc242491f622ff71291dd2785add5e9f to your computer and use it in GitHub Desktop.
Save SachaEpskamp/dc242491f622ff71291dd2785add5e9f to your computer and use it in GitHub Desktop.
qgraph network comparison app
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("BFI network comparison"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("constraint",
"Constraint",
min = 0,
max = 10,
value = 1,
step = 0.1)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$plot <- renderPlot({
layout(t(1:2))
qgraph(graph1$graph, layout = "spring",
layout.par = list(init=L, max.delta = 25/10^input$constraint), cut=0, theme = "colorblind", maximum = Max)
qgraph(graph2$graph, layout = "spring",
layout.par = list(init=L, max.delta = 25/10^input$constraint), cut=0, theme = "colorblind", maximum = Max)
})
}
global <- function(){
library(psych)
library(qgraph)
library(bootnet)
data(bfi)
bfi1 <<- bfi[bfi$gender==1,1:25]
bfi2 <<- bfi[bfi$gender==2,1:25]
graph1 <<- estimateNetwork(bfi1, default = "EBICglasso")
graph2 <<- estimateNetwork(bfi2, default = "EBICglasso")
Max <<- max(graph1$graph, graph2$graph)
# Average layout:
L <<- qgraph((graph1$graph+graph2$graph)/2, layout = "spring",DoNotPlot=TRUE)$layout.orig
}
# Run the application
shinyApp(ui = ui, server = server,onStart = global)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment