title: isolate vs reactive in shiny
body: <p>I am building a simple <strong>shiny</strong> app to display centrality measures on a network chosen by the user. The user chooses the network format, the file of the network, and the centrality measure to compute, and then clicks a button to layout and visualize the graph where size of nodes is proportional to node's centrality. In the <code>renderPlot</code> output I isolated all the inputs but the button, so that the computation is done only when the user has chosen the relevant information (format, file, measure) and clicks the visualize button. It works but with the following problem: each time the visualize button is clicked, the layout is recomputed and the network is visualized in a different way. I would like to avoid this behaviour. I tried to include the layout computation in a <code>reactive</code> call (see commented code), but then the isolation fails.
  Hence I am able to <strong>isolate</strong> but not make the code <strong>reactive</strong>, or to make it reactive without isolation. </p>
  
  <p>The UI code follows:</p>
  
  <pre><code>shinyUI(fluidPage(
  titlePanel("Visualize and compare centrality measures"),
  
  sidebarLayout(
    sidebarPanel(
  
    selectInput("format", label = h4("Select graph format"), 
                choices = c("gml", "graphml", "edgelist", "pajek", "ncol", "lgl",
                            "dimacs", "graphdb", "dl")),
  
    br(),
  
    fileInput("graph", label = h4("Load graph")),
  
    br(),
  
  
    selectInput("centrality", label = h4("Select centrality measure"), 
                choices = c("degree", "eigenvector", "Katz")),
  
    br(),
  
    conditionalPanel(
      condition = "input.centrality == 'Katz'",
      numericInput("alpha", 
                   label = h4("Alpha"), min=0, step = 0.05, 
                   value = 1)),
  
  
    actionButton("plot", "Visualize")
  
  
    ),
  mainPanel(plotOutput("net"))
  )
  ))
  </code></pre>
  
  <p>The server code follows:</p>
  
  <pre><code>library(igraph)
  # mapping k from [x,y] in [w,z] with f(k) = w + (z-w) * (k-x)/(y-x)
  map = function(k,x,y,w,z) {if (x != y) w + (z-w) * (k-x)/(y-x) else (w+z)/2}
  
  shinyServer(
  function(input, output) {
  
  # read input graph
  # g = reactive({read.graph(file=input$graph$datapath, format=input$format)});
  # compute layout
  # coords = reactive({layout.fruchterman.reingold(g)});
  
  output$net = renderPlot({
    if (input$plot &gt; 0) {
      g = isolate(read.graph(file=input$graph$datapath, format=input$format))
      coords = layout.fruchterman.reingold(g)
  
      cent = isolate(switch(input$centrality, 
                    "degree" = degree(g),
                    "eigenvector" = evcent(g)$vector,
                    "Katz" = alpha.centrality(g, alpha = input$alpha)))
  
      plot(g, layout=coords, vertex.label=NA, vertex.size = map(cent, min(cent), max(cent), 1, 10))
  
    }
  
  
  })
  } 
  )
  </code></pre>