I'm attempting to add a module to a preexisting R Shiny app to verify users through a cookie based system. To work with cookies in R Shiny, I've followed this tutorial and I've extended shinyjs with the following javascript code:
shinyjs.getcookie = function(params) {
var cookie = Cookies.get("id");
if (typeof cookie !== "undefined") {
Shiny.onInputChange("jscookie", cookie);
} else {
var cookie = "";
Shiny.onInputChange("jscookie", cookie);
}
}
shinyjs.setcookie = function(params) {
Cookies.set("id", escape(params), {
expires: 0.5
});
Shiny.onInputChange("jscookie", params);
}
shinyjs.rmcookie = function(params) {
Cookies.remove("id");
Shiny.onInputChange("jscookie", "");
}
I made a test example with a small R Shiny app that worked correctly without modules, however, when I tried to implement a module to perform the same function, I ran into an issue retrieving the cookies.
From within server.R, I can retrieve the cookies without issue using the following code:
observe({
js$getcookie()
print(input$jscookie)
})
However, when I put that same code into the module's server function, it prints out NULL every time. I believe that the problem has to do with namespaces, and that maybe input$jscookie
in server.R refers to a different thing than input$jscookie
in the module. However, I'm very new (just a few days) to Shiny modules, so I'm still unsure of some aspects of how they work.
Is there a way to retrieve the cookie from within the module?