title: shiny / rscript - reactive plot using checkboxGroupInput integer list not working
body: <p>I am developing some geo-analytical software with R-script using the rgdal, and RSAGA addon's. I have recently found the shiny addon, and I am pleased with how easy it is to wrap my loop controller in a UI. Unfortunately, I am having issues with the reactive functions required make a checkbox group of values (those being individual ecodistricts) plot a reactive preview of the outline of each selected ecodistrict in the checkbox. </p>
  
  <p>I have a checkboxGroupInput with an integer list of 110 ecodistricts (244, 278, 302, etc..) and an outputPlot handler for the reactive output. </p>
  
  <p>To get the gist, the shape file is read to extract a list of ecodistricts for the checkbox group ('ed_all'), and also extract a shape with the outline of every ecodistrict ('xcheck'). In essense, I am trying to accomplish two things:</p>
  
  <p>1 - make a reactive variable 'ed_list' which changes a list of integers as Ecodistricts are selected with the checkboxes</p>
  
  <p>2 - To do a reactive polygon intersection using the reactive variable 'ed_list' and the 'xcheck' shape, in order to plot a reactive graph of the selected ecodistricts.</p>
  
  <p>I am currently using rsaga.geoprocessor wrapped in a reactive command to do the intersection but i am open to suggestion if there is a better way. Every time i try to execute this code it gives me...</p>
  
  <p>"Error in .getReactiveEnvironment()$currentContext() : 
    Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive function.)"</p>
  
  <p>or something to that effect.</p>
  
  <p>Below is the clipped code relevant to my question:</p>
  
  <pre><code>    ui.r
  
      library(shiny)
      library(rgdal)
  
      setwd("D:\\BC_soil_map")
  
      ed &lt;- readOGR(".\\BC_data\\BC_Shapes\\BC_soils\\Soil_Polygons_SLC", layer = "EcoDistricts_BC")
      ed_all &lt;- ed$ECODISTRIC
      ed_null &lt;- ed$EDnull
  
      shinyUI(pageWithSidebar(
  
      headerPanel(div(align = "center", 
                "Soil Mapping Data-Quilt Application")), 
  
      sidebarPanel(div(align = "center",  
                       h4("Select and EcoDistrict"),
  
                       checkboxGroupInput("ed_chkbx", 
                                    label = "",
                                    choices = ed_all,
                                    selected = ed_all))),
  
      mainPanel(div(align = "center",  
                       h4("Preview"),
  
                       plotOutput("preview", 
                                  width = "500px", 
                                  height = "500px"))
  
                 ))
  </code></pre>
  
  <p>This is the server part of the code..</p>
  
  <pre><code>    server.R
  
      library(shiny)
      library(RSAGA)
      library(rgdal)
  
      setwd("D:\\BC_soil_map")
  
      ed &lt;- readOGR(".\\BC_data\\BC_Shapes\\BC_soils\\Soil_Polygons_SLC", layer = "EcoDistricts_BC")
  
      xcheck &lt;- subset(ed, select = c("ECODISTRIC","SHAPE_LENG","SHAPE_AREA"))
  
      ed_all &lt;- ed$ECODISTRIC
      ed_null &lt;- ed$EDNONE
  
      shinyServer(function(input, output, session) {
  
      x &lt;- reactiveValues(input$ed_chkbx == TRUE)
      ed_list&lt;- reactiveValuesToList(x, all.names = FALSE)
  
      previewInput &lt;- reactive({
           rsaga.geoprocessor("shapes_polygons",
                     "Polygon Intersection",
                     list(SHAPES_A=xcheck),
                     FIELD_A="ECODISTRIC",
                     SHAPES_B=ed_list(),
                     SHAPES_AB= ##THIS IS USUALLY THE DIRECTORY FOR THE OUTPUT OF THE INTERSECTED FILE##
                     METHOD=1)})
  
      output$preview &lt;- renderPlot(previewInput(), 
                             width = "150px", 
                             height = "150px", 
                             res = 72, 
                             env = parent.frame(),
                             quoted = FALSE, 
                             func = NULL)
  
      })
  </code></pre>