block by ramnathv 6144287

Google Maps with Shiny

Full Screen

This is a minor modification of this post. The basic problem is that to update the histogram, one had to (a) click on a point on the map, (2) go to the numeric input box and (3) press enter. This can be simplified by adding three pieces of code.

setValue

First, we modify the setValue function so that in addition to modifying the value of the row clicked, it also communicates this value to the Shiny input variable row.

function SetValue(i) {
    document.getElementById("row").value = i;
  Shiny.onInputChange("row", i)
    document.getElementById("row").focus();
}

observeEvent

Inside server.R, we use a function observeEvent to receive such messages, and update the input variable, which will then trigger change in the histogram through Shiny’s reactive mechanisms. Note that observeEvent is a function in server.R, but there are plans to add it to the Shiny package explicitly.

observeEvent(input$row, function(){
  updateNumericInput(session, "row", value = input$row)
})

index.html

server.r

ui.R