Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to retrieve a Javascript variable from a script to use it in R?

I'm currently developing a shiny App, and as I'm trying to use a leaflet plugin that hasn't been translated in a R package at the moment, I'm using a var map in a js script (I use this script in my UI.R), the fact is that I would like in the server part to be able to communicate with this map, with for example a leaflet proxy to add tiles on it, but I didn't manage to make the server part communicate with that Js var.

Maybe if you have a clew of what's the problem you could help me a lot.

like image 571
Killian Avatar asked Oct 15 '25 15:10

Killian


1 Answers

Yes you can do it.

ui.R

tags$script(src="demo.js")

demo.js

var map = ...
setTimeout(function() {
    Shiny.onInputChange("mapInR", map);
}, 10);

Now you can pass the value of map from javascript to R.

In server.R you just need to check for javascript value map as:

server <- function(input, output) {
    useMapInR <- reactive({ input$mapInR })
}

Now whenever value of map changes in javascript it will get reflected in useMapInR.

like image 169
skap Avatar answered Oct 17 '25 04:10

skap



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!