The way the html code is generated seems reversed to me. It seems like I'm must not understand what you mean by "value". I'm also not sure my point is exactly related to this thread, but please reply nonetheless.
Before I get started, these examples were run using shiny_0.9.1.9015
What I want is to display several long strings in a multiple selection
box. When a specific element is selected, I want the "name" of the
selected list element(s) returned in output object, not the
"displayed strings".
For example, consider this named list:
[Note that the names could be a row numbers in a (perhaps large) table;
I'd rather not have to do string matches on all the elements to find which
row(s) were selected):
theChoices <-
list(c1 = "Long string describing choice 1",
c2 = "Long string describing choice 2",
c3 = "Long string describing choice 3")
selectInput(inputId="test",label="testLabel",
choices=theChoices,selectize=FALSE)
This html code is created:
<label class="control-label" for="test">testLabel</label>
<select id="test">
<option value="Long string describing choice 1" selected>c1</option>
<option value="Long string describing choice 2">c2</option>
<option value="Long string describing choice 3">c3</option></select>
The UI does not display the long strings (what one would want),
it displays the names of the list elements, that is c1, c2, and c3.
It seems to me that when a named list is used, the html code should look like
this:
<label class="control-label" for="test">testLabel</label>
<select id="test">
<option value="c1" selected>Long string describing choice 1</option>
<option value="c2">Long string describing choice 2</option>
<option value="c3">Long string describing choice 3</option></select>
In this case, the long strings are displayed, and when one of the items
is selected by the user, the "values" are returned (ie, c1, c2,...),
not the long string.
To get what I want, I've had to duplicate my otherwise well organized lists,
reversing the names and the values, like this:
reverseNamed <- names(theChoices)
names(reverseNamed) <- theChoices
selectInput(inputId="test3",label="test3Label",
choices=reverseNamed,selectize=FALSE)
Which yields:
<label class="control-label" for="test3">test3Label</label>
<select id="test3">
<option value="c1" selected>Long string describing choice 1</option>
<option value="c2">Long string describing choice 2</option>
<option value="c3">Long string describing choice 3</option></select>
>
===========
Is this a bug or am I missing something important that everyone
else "gets with ease!". If the behavior is changed in shiny, I'll be
happy to modify my code to match.
Thanks, Nick Crookston