title: Passing json/data to a javascript object with shiny
body: <p>I'm trying to figure out how to get R to interact via shiny with other javascript elements, which I'm guessing means by having <code>server.R</code> serve a customised shiny object (ideally json formatted?) to <code>ui.R</code>, which is then converted to a javascript array.  My work-in-progress code is:</p>
  
  <p><strong>server.R</strong></p>
  
  <pre><code>library(shiny)
  
  shinyServer(
    function(input, output) {
      output$species_table &lt;- renderTable({ iris[iris$Species == input$species,] })
      output$json &lt;- RJSONIO::toJSON(iris[iris$Species == input$species,], byrow=T, colNames=T) # error line
    }
  )
  </code></pre>
  
  <p><strong>ui.R</strong></p>
  
  <pre><code>require(shiny)
  specs = as.character(unique(iris$Species))
  names(specs) = specs
  
  pageWithSidebar(
    headerPanel("minimal json handling example"), 
    sidebarPanel(selectInput("species", "Species", specs)),
    mainPanel(
      tableOutput("species_table")
    )
  )
  </code></pre>
  
  <p>Which returns the server error: </p>
  
  <pre><code>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 expression or observer.)
  </code></pre>
  
  <p>.. because it's obviously the wrong approach.  Without <em>server.R</em>'s line <code>output$json &lt;- ...</code> the outcome works and <a href="https://geotheory.shinyapps.io/example1/" rel="nofollow">looks like this</a>, so the rest of the code is ok.  But I also want to get the json (or any alternative format) across somehow and trigger a subsequent javascript action to read it in as an array object.  Grateful for any pointers, and apologies in advance if my description is unclear.</p>