# Create mock data for Filter_long_hierarchy
Filter_long_hierarchy <- data.frame(
Parent_ID = c("01-M1", "01-M2", "01-M3", "06-M1", "06-M2"),
Seed = c("Seed1", "Seed2", "Seed3", "Seed4", "Seed5"),
Wave = c(1, 2, 1, 2, 3)
)
ui <- fluidPage(
titlePanel("RDS ID Network Visualization"),
sidebarLayout(
sidebarPanel(
selectInput(
"filter_group",
"Select Filter Group:",
choices = c("All Networks", unique(Filter_long_hierarchy$Parent_ID)),
selected = "All Networks"
)
),
mainPanel(
plotOutput("graphPlot") # Display the graph
)
)
)
server <- function(input, output) {
# Reactive data filtering based on dropdown
filtered_hierarchy <- reactive({
if (input$filter_group == "All Networks") {
Filter_long_hierarchy # Show all networks
} else {
Filter_long_hierarchy %>%
filter(Parent_ID == input$filter_group) # Filter based on selected group
}
})
# Render the graph
output$graphPlot <- renderPlot({
hierarchy <- filtered_hierarchy()
network_graph <- graph_from_data_frame(hierarchy, directed = TRUE)
ggraph(network_graph, layout = "tree") +
geom_edge_link(color = "gray", arrow = arrow(length = unit(1, 'mm')), alpha = 1) +
geom_node_point(size = 5, color = "skyblue") +
geom_node_text(aes(label = name), repel = TRUE, size = 3, max.overlaps = 50) +
theme_void() +
ggtitle(paste("Network for Group:", input$filter_group))
})
}
# Run the App
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents