yihui/shiny — pull request #3 by killkeeper (2014-08-04 01:37:06+00:00)
Title: Hotfix: fixed an error with selectizeInput() caused by RJSONIO:::fromJSON() 

This commit attempted to fix an error caused by RJSONIO:::fromJSON().

### The culprit
The function `RJSONIO:::fromJSON` is inherently buggy when decoding a stringified string, for instance:

> RJSONIO:::fromJSON('"name"')
Error in file(con, "r") : cannot open the connection

You may also notice how perplexing the error information is, which confounded me for a quite a while.
This bug with `fromJSON` has a cascaing effect: it causes the `selectizeJSON` function [to fail](https://github.com/yihui/shiny/blob/master/R/update-input.R#L448).

### An error case
A user may have this seemingly innocuous code snippet in his or her Shiny application:

```
updateSelectizeInput(
session, 'gene_list', server=T,
choices=gene.isoforms,
options=list(
searchField="gene",
render=I(
"{
option: function(item, escape) {
return '

' + escape(item.gene) + '
' +
'' + escape(item.nisoforms) + ' isoforms

';
}
}")
)
)
```

Notice that the option `searchField` is a character vector of length 1, and when when sent to the client side as JSON object, it will be translated into:

```

```

When the `searchField` is submitted to the Shiny server side as an AJAX request, the `searchField` is treated as a string instead of an array (of length 1, enclosing the string `"gene"`), triggering the aforementioned error with `fromJSON` function.

### Solution
This commit adds a sanity check within `shiny.js`: if `searchField` is a string, it will be wrapped into an array to avoid the JSON decoding error.
The author acknowledged that it is not the only way to fix this error, one can certainly address this error in R.

### A sidenote
Before patching the Javscript, I tried to come up with a workaround by specifying `searchField` as:

```
searchField=list(gene="gene")
```

However, while the above parameter can avoid triggering the decoding error, it will cause the downstream `selectize.js` rendering to malfunction. (I haven't fully investigated exactly why, this is merely an observation).

Hence, the patch provided by this commit is necessary, if the user only wants to specify a single column (attribute) for the `searchField` option.