oups, In the last line, I mean input$params[[]].
Le mercredi 18 septembre 2013 15:21:22 UTC-4, Massi a écrit :Hi,I'm trying to get multiple inputs into the same variable but it seems something is wrong with my approach!It has to be noted that the number of inputs is dynamic. The user may add an undefined number of params.Here is my code:# html client:...<input type="text" name="params[]" class="shiny-bound-input"><input type="text" name="params[]" class="shiny-bound-input"><input type="text" name="params[]" class="shiny-bound-input">...In the server side I'm using input$params[] to get an array of the values submitted by the user. But it does not seem to work. I also tried using input$lsub2[[]]Any help?Thanks!
Thank you for the replay,My understanding is that input elements are bound using their names (source: http://rstudio.github.io/shiny/tutorial/#html-ui):"HTML form elements (in this case a select list and a number input) are bound to input slots using theirname
attribute."
Thank you for the replay,My understanding is that input elements are bound using their names (source: http://rstudio.github.io/shiny/tutorial/#html-ui):"HTML form elements (in this case a select list and a number input) are bound to input slots using theirname
attribute."
Le jeudi 19 septembre 2013 00:14:49 UTC-4, ZJ a écrit :
Here is my first attempt to implement a custom component to deal with input arrays:# input-array.js:// inspiration: textInputArrayBinding and dateRangeInputBinding : https://github.com/rstudio/shiny/blob/master/inst/www/shared/shiny.js#L105var textInputArrayBinding = {};$.extend(textInputArrayBinding, {// how to find the componentfind: function(scope) {return $(scope).find('.shiny-array-input');},// Return the values in an arraygetValue: function(el) {var $objs = $('input:text[name=' + el.id + ']');var values = $inputs.map(function(){return $(this).val();}).get();return values;},// value must be an array of valuessetValue: function(el, value) {// Clear all inputs$('input:text[name=' + el.id + ']').val('');// Accept arrayif (value instanceof Array) {for (var i = 0; i < value.length; i++) {$('input:text[name=' + el.id + ']')[i].val(value[i]);}// Else assume it's a single value} else {$('input:text[name=' + el.id + ']').val(value);}},// the values are in the "values" variablegetState: function(el) {var $objs = $('input:text[name=' + el.id + ']');// Store values in an array of objects, each with value and labelvar values = new Array($objs.length);for (var i = 0; i < values.length; i++) {values[i] = {value: $objs[i].value,label: $objs[i].parent().parent().find('label[for=' + el.id + ']').text()label: this._getLabel($objs[i])};}return { label: $(el).find('label[for=' + el.id + ']').text(),value: this.getValue(el),values: values};},receiveMessage: function(el, data) {var $el = $(el);// This will replace all the valuesif (data.hasOwnProperty('values')) {for (var i = 0; i < data.values.length; i++) {$('input:text[name=' + el.id + ']')[i].val(data.values[i]);}}if (data.hasOwnProperty('value')) this.setValue(el, data.value);if (data.hasOwnProperty('label')) $el.find('label[for=' + el.id + ']').text(data.label);$(el).trigger('change');},subscribe: function(el, callback) {$(el).on('change.textInputArrayBinding', function(event) {callback();});},unsubscribe: function(el) {$(el).off('.textInputArrayBinding');},// Given an input DOM object, get the associated label. Handles labels// that wrap the input as well as labels associated with 'for' attribute._getLabel: function(obj) {// If <input id='myid'><label for='myid'>label text</label>var $label_for = $('label[for=' + obj.id + ']');if ($label_for.length > 0) {return $.trim($label_for.text());}// If <label><input /><span>label text</span></label>if (obj.parentNode.tagName === "LABEL") {return $.trim($(obj.parentNode).find('span').text());}return null;},// Given an input DOM object, set the associated label. Handles labels// that wrap the input as well as labels associated with 'for' attribute._setLabel: function(obj, value) {// If <input id='myid'><label for='myid'>label text</label>var $label_for = $('label[for=' + obj.id + ']');if ($label_for.length > 0) {$label_for.text(value);}// If <label><input /><span>label text</span></label>if (obj.parentNode.tagName === "LABEL") {$(obj.parentNode).find('span').text(value);}return null;}});Shiny.inputBindings.register(textInputArrayBinding, 'shiny.textInputArray');Shiny.inputBindings.setPriority("shiny.textInputArray", 10);# HTML sample:...<script src="assets/js/input-array.js" type="text/javascript"></script>...<div class="shiny-array-input" id="array1"><div class="control-group"><label class="control-label span3" for="array1">Array1:</label><div class="controls"><span id="addVar" class="btn btn-primary"><i class="icon-plus icon-white"></i> Add parameter</span></div></div><div class="control-group"><label class="control-label span3" ></label><div class="controls"><input type="text" name="array1" ><span class=" btn btn-danger removeVar"><i class="icon-minus icon-white"></i> Remove parameter</span></div></div><div class="control-group"><label class="control-label span3"></label><div class="controls"><input type="text" name="array1" ><span class=" btn btn-danger removeVar"><i class="icon-minus icon-white"></i> Remove parameter</span></div></div></div>However, it does not seem to work.--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.