Display and hide edges between nodes in a process_map oject based on selectInput()

Viewed 19

I have the shiny app below in which I create a process map. What I want to do is subset this process map based on the transitions selectInput(). What I acually need is to hide/display the edges between the nodes if deselect/select one transition pair

All the transitions can be seen from the obect edges which I extract from the process_map() object at the beginning.

library(shiny)
library(bupaR)
library(svgPanZoom)
library(DiagrammeRsvg)
library(processmapR)
library(DiagrammeR)
f <- \(data, nofrom, noto) {
  u <- attr(data, 'edges')
  `attr<-`(data, 'edges', u[u$from != nofrom & u$to != noto,,drop=FALSE])
}

edges<-patients %>%
  process_map(performance(mean, "days"))
edges <- attr(edges, "edges")
colnames(edges)[1]<-"predecessor"
colnames(edges)[2]<-"successor"

ui <-shinyUI(fluidPage(
  
  
  selectInput("tran","transitions",choices = paste(edges$predecessor,"-",edges$successor),
              selected = paste(edges$predecessor,"-",edges$successor),multiple = T),
  svgPanZoomOutput("pmap",height = 500,width = 1600)
  
))
server <- function(input, output) {
  output$pmap <- renderSvgPanZoom({
    req(input$tran)
    pre <- strsplit(input$tran, " - ")[[1]][[1]]
    suc <- strsplit(input$tran, " - ")[[1]][[2]]
    p<-process_map(patients, type_nodes = frequency("absolute",color_scale = "Greys")
                ,type_edges = frequency("absolute",color_edges = "Greys"),
                rankdir = "LR", render = FALSE)
    p1<-f(data=p, nofrom=pre, noto=suc)
    
    p1%>% generate_dot() %>% 
      grViz(width = 1000, height = 2000) %>% export_svg %>% 
      svgPanZoom(height=800, controlIconsEnabled = TRUE)
  })
}
shinyApp(ui=ui,server=server)
0 Answers
Related