2

I need to use:

session$clientData$url_search

which is a reactive expression but I don't want to use it in a reactive wrapper, i.e.

sessionData <- reactive({
  sessionData <- session$clientData$url_search
})

is there a way to now use this session data in a non reactive way? i.e.

url <- paste("http://example.web.ninja/,sessionData,sep="")
URLdata <- fromJSON(file=url,method='C')

without having to use:

URLdata <- reactive({
    url <- paste("http://example.web.ninja/,sessionData(),sep="")
    URLdata <- fromJSON(file=url,method='C')
 })

Thanks

James Willcox
  • 631
  • 1
  • 10
  • 15
  • Why do you want to do this? – jdharrison Sep 03 '14 at 23:17
  • I'm editing an older app that I made a while ago so that it now downloads its data from the web instead of the CSV file that I continued to update. I want to do it because if I wrap URL data up in a reactive wrapper I continue to get errors like : Error in URLdata$Name : object of type closure is not subsettable – James Willcox Sep 03 '14 at 23:23
  • Have also tried the solution to this problem:http://stackoverflow.com/questions/15327506/r-shiny-how-to-save-input-data-to-the-server-or-access-input-variables-globally?rq=1 by trying to set the variables globally by using <<- but that did not work either – James Willcox Sep 03 '14 at 23:31
  • `Error in URLdata$Name ...` would indicate that the way to access the variable would be `URLdata()$Name` – jdharrison Sep 04 '14 at 00:07
  • That works ok until I then create a database using that reactive expression: I create a loop to unpack the JSON file: for(j in 1:numObs[1,tx]){ df[index,1] <- URLdata$Transformers[[i]]$Name df[index,2] <- URLdata$Transformers[[i]]$dga[[j]]$Sampledate ... ect how would it work in that context where I have a 16x11 dataframe – James Willcox Sep 04 '14 at 00:24
  • You can use `isolate` if you want to stop a chain of reactivity. So access the object with `isolate(URLdata()$Name)` and it wont be treated as a reactive variable within the reactive environment its called in. – jdharrison Sep 04 '14 at 00:25

1 Answers1

4

In this case the error:

Error in URLdata$Name : object of type closure is not subsettable

indicates that the object needs to be referenced as

URLdata()$Name

This results in a call to the reactive function. Calling a reactive variable within a reactive environment endows that reactive environment with a dependency on that reactive variable. Quickly things can cascade so there is a handy function isolate which allows one to call a reactive variable in a reactive environment and not bestow that dependency. In your case accessing the required object using

isolate(URLdata()$Name)

may be what you want.

jdharrison
  • 30,085
  • 4
  • 77
  • 89