I would like to pass a vector to extendshinyjs
as a JS array, but it seems that the vector is actually passed as a string.
Here is my code:
ui.R
shinyUI( fluidPage(
useShinyjs(),
extendShinyjs(text = jsCode),
tags$div('color names',
tags$p(class='colorName'),
tags$p(class='colorName'),
tags$p(class='colorName')
)
))
server.R
shinyServer(
function(input,output,session) {
x <- c('red', 'yellow', 'green')
js$pageCol(x)
})
global.R
library(shinyjs)
library(shiny)
jscode <- jsCode <- "shinyjs.pageCol = function(params){
var $spots = $('p').text(params);
defaultParams = ['NA','NA','NA'];
val = shinyjs.getParams(params, defaultParams);
$spots.each(function(i) {
$(this).text(val[i]);
});
}"
On the right what it looks like now, on the left what I would expect to see
The vector is not getting passed as a string, it is being converted to a javascript array. The javascript parameter is an array with one element, where that element is the vector that you passed in (just as I told you in the other thread - I wasn't lying!)
Try this: