I'm getting started with Shiny and loving it. But I've come upon a stumbling point with incorporating javascript in my Shiny applications to add on some additional functionality. Hoping to get some help.
Here's a very basic Shiny application I'm using to test the feasibility of reading in a browser cookie with javascript so it can be accessed in ui.R.
The ui.R code.
# UI file of getCookie Shiny application.
shinyUI(fluidPage(
titlePanel('Cookie'),
cookie <- tags$head(tags$script(src='readCookie.js')),
print(cookie)
))
The javascript function included with the 'script' tag - taken from quirksmode.org/js/cookies.html.
function readCookie() {
name = "raisinCookie";
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
And the server code.
# Server file of getCookie Shiny application.
shinyServer(function(input, output){
})
First off I should ask if it's even possible to read cookies in to a shiny application? Second, am I on the right track here? Third - assuming my js code was working properly - how could I access the value returned by a js function within the shiny code it's sourced in?
Any and all help appreciated, constructive criticism as well. I'm new, so any pointers to help w/ integerating Shiny and JS are welcome.