Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a value from Server.R into .js file

I think's it's quite an easy one but I can't find a way to solve it myself. I'd like to access the value of a variable in my Server.R file (I'm using Shiny) in my javascript file. My var "i" in myFile.js should take the value of my R variable "number". How should I proceed ?

Example :

Server.R

...
number <- 5
...

myFile.js

...
var i = ??? // var i = number *is not working* 
...

Thanks for your help,

Matt

like image 740
mbh86 Avatar asked Oct 23 '25 17:10

mbh86


1 Answers

Thanks to jdharrison, it works when I add the following code in myFile.js :

Server.R

number <- 5
observe({
   session$sendCustomMessage(type='myCallbackHandler', number) 
})

myFile.js

var i ;
Shiny.addCustomMessageHandler("myCallbackHandler",     
    function(number) {
     i = number;
    }
);

var i now takes the value 5 in my javascript file.

like image 110
mbh86 Avatar answered Oct 26 '25 07:10

mbh86



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!